-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhuman-body-segment.go
56 lines (51 loc) · 1.6 KB
/
human-body-segment.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
50
51
52
53
54
55
56
package faceplusplus_client
import (
"bytes"
"encoding/base64"
"net/http"
)
func (self *fppClient) DetectHumanBodySegment(filename string) (response DetectHumanBodySegmentReponse, e error) {
body := &bytes.Buffer{}
if contentType, err := self.newRequestBodyWithInputFile(filename, body); err == nil {
if rsp, err := self.detectHumanBodySegment(body, contentType); err == nil {
response = rsp
} else {
e = err
}
} else {
e = err
}
return
}
func (self *fppClient) DetectHumanBodySegmentWithImageData(imageData []byte) (response DetectHumanBodySegmentReponse, e error) {
body := &bytes.Buffer{}
imageDataEncoded := base64.StdEncoding.EncodeToString(imageData)
if contentType, err := self.newRequestBodyWithParameters(map[string]string{"image_base64": imageDataEncoded}, body); err == nil {
if rsp, err := self.detectHumanBodySegment(body, contentType); err == nil {
response = rsp
} else {
e = err
}
} else {
e = err
}
return
}
func (self *fppClient) detectHumanBodySegment(body *bytes.Buffer, contentType string) (response DetectHumanBodySegmentReponse, e error) {
if request, err := http.NewRequest("POST", DETECT_HUMAN_BODY_SEGMENT_URL, body); err == nil {
if err := self.executeRequest(request, contentType, &response); err == nil {
} else {
e = err
}
} else {
e = err
}
return
}
type DetectHumanBodySegmentReponse struct {
TimeUsed int `json:"time_used",omitempty`
ImageId string `json:"image_id",omitempty`
Result string `json:"result",omitempty`
BodyImage string `json:"body_image",omitempty`
ErrorMessage string `json:"error_message",omitempty`
}