forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
26 lines (22 loc) · 870 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
package opencv
import (
cv "github.com/lazywei/go-opencv/opencv"
)
// loadHaarClassifierCascade returns open cv HaarCascade loaded
func loadHaarClassifierCascade(haar string) *cv.HaarCascade {
return cv.LoadHaarClassifierCascade(haar)
}
// DetectFaces loads Haar cascade to detect face objects in image
func DetectFaces(haar string, image *cv.IplImage) []*cv.Rect {
return loadHaarClassifierCascade(haar).DetectObjects(image)
}
// DrawRectangles uses Rect array values to return image with rectangles drawn.
func DrawRectangles(image *cv.IplImage, rect []*cv.Rect, r int, g int, b int, thickness int) *cv.IplImage {
for _, value := range rect {
cv.Rectangle(image,
cv.Point{value.X() + value.Width(), value.Y()},
cv.Point{value.X(), value.Y() + value.Height()},
cv.NewScalar(float64(b), float64(g), float64(r), 0), thickness, 1, 0)
}
return image
}