forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencv_face_detect.go
49 lines (37 loc) · 945 Bytes
/
opencv_face_detect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"path"
"runtime"
"time"
cv "github.com/lazywei/go-opencv/opencv"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/opencv"
)
func main() {
_, currentfile, _, _ := runtime.Caller(0)
cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
gbot := gobot.NewGobot()
window := opencv.NewWindowDriver("window")
camera := opencv.NewCameraDriver("camera", 0)
work := func() {
var image *cv.IplImage
gobot.On(camera.Event("frame"), func(data interface{}) {
image = data.(*cv.IplImage)
})
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)
}
})
}
robot := gobot.NewRobot("faceBot",
[]gobot.Connection{},
[]gobot.Device{window, camera},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}