-
Notifications
You must be signed in to change notification settings - Fork 1
/
human-body-skeleton.go
87 lines (79 loc) · 3.06 KB
/
human-body-skeleton.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package faceplusplus_client
import (
"bytes"
"encoding/base64"
"net/http"
)
func (self *fppClient) DetectSkelethon(filename string) (response DetectHumanBodySkeletonReponse, e error) {
body := &bytes.Buffer{}
if contentType, err := self.newRequestBodyWithInputFile(filename, body); err == nil {
if rsp, err := self.detectHumanBodySkeleton(body, contentType); err == nil {
response = rsp
} else {
e = err
}
} else {
e = err
}
return
}
func (self *fppClient) DetectSkeletonWithImageData(imageData []byte) (response DetectHumanBodySkeletonReponse, 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.detectHumanBodySkeleton(body, contentType); err == nil {
response = rsp
} else {
e = err
}
} else {
e = err
}
return
}
func (self *fppClient) detectHumanBodySkeleton(body *bytes.Buffer, contentType string) (response DetectHumanBodySkeletonReponse, e error) {
if request, err := http.NewRequest("POST", DETECT_HUMAN_BODY_SKELETON_URL, body); err == nil {
if err := self.executeRequest(request, contentType, &response); err == nil {
} else {
e = err
}
} else {
e = err
}
return
}
type HumanBodySkeletonLandmarkPoint struct {
X int `json:"x",omitempty`
Y int `json:"y",omitempty`
Score float32 `json:"score",omitempty`
}
type HumanBodySkeleton struct {
BodyRectangle struct {
Top int `json:"top",omitempty`
Left int `json:"left",omitempty`
Width int `json:"width",omitempty`
Height int `json:"height",omitempty`
} `json:"body_rectangle",omitempty`
Landmark HumanBodySkeletonLandmark `json:"landmark",omitempty`
}
type HumanBodySkeletonLandmark struct {
Head HumanBodySkeletonLandmarkPoint `json:"head",omitempty`
Neck HumanBodySkeletonLandmarkPoint `json:"neck",omitempty`
LeftElbow HumanBodySkeletonLandmarkPoint `json:"left_elbow",omitempty`
LeftButtocks HumanBodySkeletonLandmarkPoint `json:"left_buttocks",omitempty`
LeftShoulder HumanBodySkeletonLandmarkPoint `json:"left_shoulder",omitempty`
LeftKnee HumanBodySkeletonLandmarkPoint `json:"left_knee",omitempty`
LeftHand HumanBodySkeletonLandmarkPoint `json:"left_hand",omitempty`
LeftFoot HumanBodySkeletonLandmarkPoint `json:"left_foot",omitempty`
RightElbow HumanBodySkeletonLandmarkPoint `json:"right_elbow",omitempty`
RightButtocks HumanBodySkeletonLandmarkPoint `json:"right_buttocks",omitempty`
RightShoulder HumanBodySkeletonLandmarkPoint `json:"right_shoulder",omitempty`
RightKnee HumanBodySkeletonLandmarkPoint `json:"right_knee",omitempty`
RightHand HumanBodySkeletonLandmarkPoint `json:"right_hand",omitempty`
RightFoot HumanBodySkeletonLandmarkPoint `json:"right_foot",omitempty`
}
type DetectHumanBodySkeletonReponse struct {
TimeUsed int `json:"time_used",omitempty`
ImageId string `json:"image_id",omitempty`
Skeletons []HumanBodySkeleton `json:"skeletons",omitempty`
}