-
Notifications
You must be signed in to change notification settings - Fork 10
/
face_faceshape.go
49 lines (45 loc) · 1.26 KB
/
face_faceshape.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package txai
import (
"encoding/base64"
"fmt"
"io/ioutil"
)
var (
faceFaceshapeURI = "/face/face_faceshape"
)
// FaceFaceshapeForBase64 五官定位 - 图片为base64格式
// image 图片base64后字符串
// modes 检测模式,0-正常,1-大脸模式(默认1)
func (ai *TxAi) FaceFaceshapeForBase64(image string, modes ...int) (*FaceFaceshapeResponse, error) {
mode := 1
if len(modes) > 0 {
mode = modes[0]
}
params := ai.getPublicParams()
params.Add("image", image)
params.Add("mode", fmt.Sprint(mode))
sign := ai.getReqSign(params)
params.Add("sign", sign)
// 响应结果
faceFaceshapeResponse := new(FaceFaceshapeResponse)
err := ai.RequestAPI(faceFaceshapeURI, params, faceFaceshapeResponse)
if err != nil {
return nil, err
}
return faceFaceshapeResponse, nil
}
// FaceFaceshapeForPath 五官定位 - 图片为本地路径
// imagePath 本地图片路径
// modes 检测模式,0-正常,1-大脸模式(默认1)
func (ai *TxAi) FaceFaceshapeForPath(imagePath string, modes ...int) (*FaceFaceshapeResponse, error) {
mode := 1
if len(modes) > 0 {
mode = modes[0]
}
body, err := ioutil.ReadFile(imagePath)
if err != nil {
return nil, err
}
img := base64.StdEncoding.EncodeToString(body)
return ai.FaceFaceshapeForBase64(img, mode)
}