Skip to content

Commit

Permalink
opencv: OpenCV face detector that is much more concurrent
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 5, 2017
1 parent 2929791 commit a998b0b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/opencv_face_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ package main
import (
"path"
"runtime"
"sync/atomic"
"time"

"github.com/hybridgroup/gocv"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/opencv"
)

var img atomic.Value

func main() {
_, currentfile, _, _ := runtime.Caller(0)
cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
Expand All @@ -21,8 +25,19 @@ func main() {
camera := opencv.NewCameraDriver(1)

work := func() {
mat := gocv.NewMat()
img.Store(mat)

camera.On(opencv.Frame, func(data interface{}) {
i := data.(gocv.Mat)
img.Store(i)
})

gobot.Every(10*time.Millisecond, func() {
i := img.Load().(gocv.Mat)
if i.Empty() {
return
}
faces := opencv.DetectFaces(cascade, i)
opencv.DrawRectangles(i, faces, 0, 255, 0, 5)
window.ShowImage(i)
Expand Down

0 comments on commit a998b0b

Please sign in to comment.