-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbody_part.go
More file actions
59 lines (52 loc) · 1.39 KB
/
body_part.go
File metadata and controls
59 lines (52 loc) · 1.39 KB
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
package openpose
import "fmt"
// BodyPart represents body part
type BodyPart struct {
// Part CocoPart
Part CocoPart
// Point coordinate of body part
Point Point
// Score confidence score
Score float32
}
// NewBodyPart returns a new BodyPart
func NewBodyPart(part CocoPart, point Point, score float32) BodyPart {
return BodyPart{
Part: part,
Point: point,
Score: score,
}
}
// String return BodyPart string representation
func (b BodyPart) String() string {
return fmt.Sprintf("BodyPart:%d-(%.2f, %.2f) score:%.4f", b.Part, b.Point.X, b.Point.Y, b.Score)
}
// BodyPartID returns a BodyPart.ID with given CocoPart and index
func BodyPartID(humanID int, part CocoPart) string {
return fmt.Sprintf("%d-%d", humanID, part)
}
// BodyPartPair ...
type BodyPartPair struct {
Parts [2]CocoPart
Points [2]Point
Score float64
}
// BodyPartsPoints return body part points
func BodyPartsPoints(parts []BodyPart) ([]Point, []bool) {
mp := make(map[CocoPart]BodyPart, len(parts))
for _, part := range parts {
mp[part.Part] = part
}
points := make([]Point, 0, len(PartPairs))
visibility := make([]bool, 0, len(PartPairs))
for _, pair := range PartPairs {
if part, found := mp[pair.CocoPart]; found {
points = append(points, part.Point)
visibility = append(visibility, true)
continue
}
points = append(points, ZP)
visibility = append(visibility, false)
}
return points, visibility
}