Skip to content

Commit

Permalink
opencv: all examples using new GoCV based code
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 c492ec4 commit 3e4f5a2
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions examples/ardrone_face_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"runtime"
"time"

cv "github.com/lazywei/go-opencv/opencv"
"github.com/hybridgroup/gocv"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/opencv"
"gobot.io/x/gobot/platforms/parrot/ardrone"
Expand All @@ -30,11 +30,12 @@ func main() {
work := func() {
detect := false
drone.TakeOff()
var image *cv.IplImage
var img gocv.Mat
camera.On(opencv.Frame, func(data interface{}) {
image = data.(*cv.IplImage)
img = data.(gocv.Mat)
if !detect {
window.ShowImage(image)
window.IMShow(img)
window.WaitKey(1)
}
})
drone.On(ardrone.Flying, func(data interface{}) {
Expand All @@ -44,28 +45,29 @@ func main() {
detect = true
gobot.Every(300*time.Millisecond, func() {
drone.Hover()
i := image
i := img
faces := opencv.DetectFaces(cascade, i)
biggest := 0
var face *cv.Rect
var face image.Rectangle
for _, f := range faces {
if f.Width() > biggest {
biggest = f.Width()
face = f
}
}
if face != nil {
opencv.DrawRectangles(i, []*cv.Rect{face}, 0, 255, 0, 5)
centerX := float64(image.Width()) * 0.5
turn := -(float64(face.X()) - centerX) / centerX
opencv.DrawRectangles(i, []img.Rectangle{face}, 0, 255, 0, 5)
centerX := float64(img.Size()).X * 0.5
turn := -(float64(face.Min.X - centerX) / centerX
fmt.Println("turning:", turn)
if turn < 0 {
drone.Clockwise(math.Abs(turn * 0.4))
} else {
drone.CounterClockwise(math.Abs(turn * 0.4))
}
}
window.ShowImage(i)
window.IMShow(i)
window.WaitKey(1)
})
gobot.After(20*time.Second, func() { drone.Land() })
})
Expand Down

0 comments on commit 3e4f5a2

Please sign in to comment.