1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/examples/opencv_face_detect.go

49 lines
948 B
Go
Raw Normal View History

package main
import (
cv "github.com/hybridgroup/go-opencv/opencv"
"github.com/hybridgroup/gobot"
2014-05-22 21:39:15 -07:00
"github.com/hybridgroup/gobot/platforms/opencv"
"path"
"runtime"
2014-06-08 18:14:18 -07:00
"time"
)
func main() {
_, currentfile, _, _ := runtime.Caller(0)
cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
2014-05-22 20:53:15 -07:00
gbot := gobot.NewGobot()
2014-05-22 20:53:15 -07:00
window := opencv.NewWindowDriver("window")
camera := opencv.NewCameraDriver("camera", 0)
work := func() {
var image *cv.IplImage
2014-06-08 18:14:18 -07:00
2014-07-08 18:36:14 -07:00
gobot.On(camera.Event("frame"), func(data interface{}) {
image = data.(*cv.IplImage)
})
2014-06-08 18:14:18 -07:00
gobot.Every(500*time.Millisecond, func() {
if image != nil {
i := image.Clone()
faces := opencv.DetectFaces(cascade, i)
i = opencv.DrawRectangles(i, faces, 0, 255, 0, 5)
window.ShowImage(i)
}
2014-06-08 18:14:18 -07:00
})
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot("faceBot",
[]gobot.Connection{},
[]gobot.Device{window, camera},
work,
)
gbot.AddRobot(robot)
2014-05-22 20:53:15 -07:00
gbot.Start()
}