hybridgroup.gobot/platforms/opencv/utils.go

27 lines
870 B
Go
Raw Normal View History

2014-04-28 07:58:34 +08:00
package opencv
import (
cv "github.com/lazywei/go-opencv/opencv"
)
// loadHaarClassifierCascade returns open cv HaarCascade loaded
2014-04-28 07:58:34 +08:00
func loadHaarClassifierCascade(haar string) *cv.HaarCascade {
return cv.LoadHaarClassifierCascade(haar)
}
// DetectFaces loads Haar cascade to detect face objects in image
2014-04-28 07:58:34 +08:00
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.
2014-04-28 07:58:34 +08:00
func DrawRectangles(image *cv.IplImage, rect []*cv.Rect, r int, g int, b int, thickness int) *cv.IplImage {
for _, value := range rect {
2014-04-28 07:58:34 +08:00
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
}