2014-04-28 07:58:34 +08:00
|
|
|
package opencv
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
import (
|
2016-02-20 10:36:33 +08:00
|
|
|
cv "github.com/lazywei/go-opencv/opencv"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
2014-10-21 00:23:33 +08:00
|
|
|
// loadHaarClassifierCascade returns open cv HaarCascade loaded
|
2014-04-28 07:58:34 +08:00
|
|
|
func loadHaarClassifierCascade(haar string) *cv.HaarCascade {
|
|
|
|
return cv.LoadHaarClassifierCascade(haar)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-10-21 00:23:33 +08:00
|
|
|
// 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)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-10-21 00:23:33 +08:00
|
|
|
// 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 {
|
2014-04-26 18:11:51 +08:00
|
|
|
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()},
|
2016-02-20 10:36:33 +08:00
|
|
|
cv.NewScalar(float64(b), float64(g), float64(r), 0), thickness, 1, 0)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
return image
|
|
|
|
}
|