hybridgroup.gobot/examples/opencv_face_detect.go

47 lines
926 B
Go
Raw Normal View History

package main
import (
cv "github.com/hybridgroup/go-opencv/opencv"
"github.com/hybridgroup/gobot"
2014-04-28 07:58:34 +08:00
"github.com/hybridgroup/gobot/opencv"
"path"
"runtime"
)
func main() {
_, currentfile, _, _ := runtime.Caller(0)
cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
2014-04-28 07:58:34 +08:00
window := opencv.NewWindowDriver()
window.Name = "window"
2014-04-28 07:58:34 +08:00
camera := opencv.NewCameraDriver()
camera.Name = "camera"
work := func() {
var image *cv.IplImage
gobot.On(camera.Events["Frame"], func(data interface{}) {
image = data.(*cv.IplImage)
})
go func() {
for {
if image != nil {
i := image.Clone()
2014-04-28 07:58:34 +08:00
faces := opencv.DetectFaces(cascade, i)
i = opencv.DrawRectangles(i, faces, 0, 255, 0, 5)
window.ShowImage(i)
}
}
}()
}
robot := gobot.Robot{
2014-04-28 07:58:34 +08:00
Connections: []gobot.Connection{},
Devices: []gobot.Device{window, camera},
Work: work,
}
robot.Start()
}