Add face detection
This commit is contained in:
parent
657e340eb2
commit
79f4e377a6
4 changed files with 26220 additions and 4 deletions
|
|
@ -9,6 +9,9 @@ package opencv
|
|||
//#cgo darwin pkg-config: opencv
|
||||
//#cgo windows LDFLAGS: -lopencv_core242.dll -lopencv_imgproc242.dll -lopencv_photo242.dll -lopencv_highgui242.dll -lstdc++
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
/****************************************************************************************\
|
||||
* Eigen objects *
|
||||
|
|
@ -48,6 +51,26 @@ import "C"
|
|||
/****************************************************************************************\
|
||||
* Face eyes&mouth tracking *
|
||||
\****************************************************************************************/
|
||||
type HaarCascade struct {
|
||||
cascade *C.CvHaarClassifierCascade
|
||||
}
|
||||
|
||||
func LoadHaarClassifierCascade(haar string) *HaarCascade {
|
||||
haarCascade := new(HaarCascade)
|
||||
haarCascade.cascade = C.cvLoadHaarClassifierCascade(C.CString(haar), C.cvSize(1, 1))
|
||||
return haarCascade
|
||||
}
|
||||
|
||||
func (this *HaarCascade) DetectObjects(image *IplImage) []*Rect {
|
||||
storage := C.cvCreateMemStorage(0)
|
||||
seq := C.cvHaarDetectObjects(unsafe.Pointer(image), this.cascade, storage, 1.1, 3, 0, C.cvSize(0, 0), C.cvSize(0, 0))
|
||||
var faces []*Rect
|
||||
for i := 0; i < (int)(seq.total); i++ {
|
||||
rect := (*Rect)((*_Ctype_CvRect)(unsafe.Pointer(C.cvGetSeqElem(seq, C.int(i)))))
|
||||
faces = append(faces, rect)
|
||||
}
|
||||
return faces
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* 3D Tracker *
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@
|
|||
#include <opencv/highgui.h>
|
||||
#include <opencv2/photo/photo_c.h>
|
||||
#include <opencv2/imgproc/imgproc_c.h>
|
||||
#include <opencv2/core/core_c.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/objdetect/objdetect.hpp>
|
||||
#include <opencv2/legacy/compat.hpp>
|
||||
#include <opencv2/legacy/legacy.hpp>
|
||||
|
||||
// Trackbar
|
||||
int GoOpenCV_CreateTrackbar(
|
||||
|
|
|
|||
27
samples/face_detect.go
Normal file
27
samples/face_detect.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/go-opencv/opencv"
|
||||
"path"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
_, currentfile, _, _ := runtime.Caller(0)
|
||||
image := opencv.LoadImage(path.Join(path.Dir(currentfile), "../images/lena.jpg"))
|
||||
|
||||
cascade := opencv.LoadHaarClassifierCascade(path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml"))
|
||||
faces := cascade.DetectObjects(image)
|
||||
|
||||
for _, value := range faces {
|
||||
opencv.Circle(image, opencv.Point{value.X(), value.Y()}, 2, opencv.ScalarAll(255.0), 1, 1, 0)
|
||||
opencv.Rectangle(image,
|
||||
opencv.Point{value.X() - value.Width(), value.Y() - value.Height()},
|
||||
opencv.Point{value.X() + value.Width(), value.Y() + value.Height()},
|
||||
opencv.ScalarAll(255.0), 1, 1, 0)
|
||||
}
|
||||
|
||||
win := opencv.NewWindow("Face Detection")
|
||||
win.ShowImage(image)
|
||||
opencv.WaitKey(0)
|
||||
}
|
||||
26161
samples/haarcascade_frontalface_alt.xml
Normal file
26161
samples/haarcascade_frontalface_alt.xml
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue