Skip to content

Commit 7ffcc50

Browse files
committed
Add method RenderFaceDetections
1 parent d65b255 commit 7ffcc50

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

face.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (rec *Recognizer) detectFromFile(type_ int, file string) (faces []Face, err
232232
rData := (*[1 << 30]C.long)(rDataPtr)[:rDataLen:rDataLen]
233233

234234
for i := 0; i < numFaces; i++ {
235-
face := Face{imagePointer: *ptr}
235+
face := Face{imagePointer: ptr}
236236
x0 := int(rData[i*rectLen])
237237
y0 := int(rData[i*rectLen+1])
238238
x1 := int(rData[i*rectLen+2])

gocv.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package face
1313
import "C"
1414
import (
1515
"image"
16+
"image/color"
1617
"unsafe"
1718

1819
"gocv.io/x/gocv"
@@ -62,3 +63,61 @@ func (rec *Recognizer) DetectFromMat(mat gocv.Mat) (faces []Face, err error) {
6263
func (rec *Recognizer) DetectFromMatCNN(mat gocv.Mat) (faces []Face, err error) {
6364
return rec.detectFromMat(1, mat)
6465
}
66+
67+
func RenderFaceDetections(img *gocv.Mat, Shapes []image.Point, col color.Color, thickness int) {
68+
if len(Shapes) == 5 {
69+
gocv.Line(img, Shapes[0], Shapes[1], col, thickness)
70+
gocv.Line(img, Shapes[1], Shapes[4], col, thickness)
71+
gocv.Line(img, Shapes[4], Shapes[3], col, thickness)
72+
gocv.Line(img, Shapes[3], Shapes[2], col, thickness)
73+
} else {
74+
// Around Chin. Ear to Ear
75+
for i := 1; i <= 16; i++ {
76+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
77+
}
78+
79+
// Line on top of nose
80+
for i := 28; i <= 30; i++ {
81+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
82+
}
83+
84+
// left eyebrow
85+
for i := 18; i <= 21; i++ {
86+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
87+
}
88+
// Right eyebrow
89+
for i := 23; i <= 26; i++ {
90+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
91+
}
92+
// Bottom part of the nose
93+
for i := 31; i <= 35; i++ {
94+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
95+
}
96+
// Line from the nose to the bottom part above
97+
gocv.Line(img, Shapes[30], Shapes[35], col, thickness)
98+
99+
// Left eye
100+
for i := 37; i <= 41; i++ {
101+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
102+
}
103+
gocv.Line(img, Shapes[36], Shapes[41], col, thickness)
104+
105+
// Right eye
106+
for i := 43; i <= 47; i++ {
107+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
108+
}
109+
gocv.Line(img, Shapes[42], Shapes[47], col, thickness)
110+
111+
// Lips outer part
112+
for i := 49; i <= 59; i++ {
113+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
114+
}
115+
gocv.Line(img, Shapes[48], Shapes[59], col, thickness)
116+
117+
// Lips inside part
118+
for i := 61; i <= 67; i++ {
119+
gocv.Line(img, Shapes[i], Shapes[i-1], col, thickness)
120+
}
121+
gocv.Line(img, Shapes[60], Shapes[67], col, thickness)
122+
}
123+
}

0 commit comments

Comments
 (0)