@@ -13,6 +13,7 @@ package face
13
13
import "C"
14
14
import (
15
15
"image"
16
+ "image/color"
16
17
"unsafe"
17
18
18
19
"gocv.io/x/gocv"
@@ -62,3 +63,61 @@ func (rec *Recognizer) DetectFromMat(mat gocv.Mat) (faces []Face, err error) {
62
63
func (rec * Recognizer ) DetectFromMatCNN (mat gocv.Mat ) (faces []Face , err error ) {
63
64
return rec .detectFromMat (1 , mat )
64
65
}
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