forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
35 lines (28 loc) · 876 Bytes
/
utils.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
package opencv
import (
"image"
"image/color"
"gocv.io/x/gocv"
)
var classifier *gocv.CascadeClassifier
// loadHaarClassifierCascade returns open cv HaarCascade loaded
func loadCascadeClassifier(haar string) *gocv.CascadeClassifier {
if classifier != nil {
return classifier
}
c := gocv.NewCascadeClassifier()
c.Load(haar)
classifier = &c
return classifier
}
// DetectObjects loads Haar cascade to detect face objects in image
func DetectObjects(haar string, img gocv.Mat) []image.Rectangle {
return loadCascadeClassifier(haar).DetectMultiScale(img)
}
// DrawRectangles uses Rect array values to return image with rectangles drawn.
func DrawRectangles(img gocv.Mat, rects []image.Rectangle, r int, g int, b int, thickness int) {
for _, rect := range rects {
gocv.Rectangle(&img, rect, color.RGBA{uint8(r), uint8(g), uint8(b), 0}, thickness)
}
return
}