2014-04-26 18:11:51 +08:00
|
|
|
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"
|
2014-04-26 18:11:51 +08:00
|
|
|
"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()
|
2014-04-26 18:11:51 +08:00
|
|
|
window.Name = "window"
|
|
|
|
|
2014-04-28 07:58:34 +08:00
|
|
|
camera := opencv.NewCameraDriver()
|
2014-04-26 18:11:51 +08:00
|
|
|
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)
|
2014-04-26 18:11:51 +08:00
|
|
|
window.ShowImage(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.Robot{
|
2014-04-28 07:58:34 +08:00
|
|
|
Connections: []gobot.Connection{},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{window, camera},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|