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.Events["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) } }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("faceBot", []gobot.Connection{}, []gobot.Device{window, camera}, work)) gbot.Start() }
func main() { gbot := gobot.NewGobot() window := opencv.NewWindowDriver("window") camera := opencv.NewCameraDriver("camera", 0) work := func() { gobot.On(camera.Events["Frame"], func(data interface{}) { window.ShowImage(data.(*cv.IplImage)) }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("cameraBot", []gobot.Connection{}, []gobot.Device{window, camera}, work)) gbot.Start() }
func main() { gbot := gobot.NewGobot() window := opencv.NewWindowDriver("window") camera := opencv.NewCameraDriver("camera", 0) work := func() { gobot.On(camera.Event("frame"), func(data interface{}) { window.ShowImage(data.(*cv.IplImage)) }) } robot := gobot.NewRobot("cameraBot", []gobot.Device{window, camera}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) gbot := gobot.NewGobot() _, currentfile, _, _ := runtime.Caller(0) cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml") window := opencv.NewWindowDriver("window") camera := opencv.NewCameraDriver("camera", "tcp://192.168.1.1:5555") ardroneAdaptor := ardrone.NewArdroneAdaptor("Drone") drone := ardrone.NewArdroneDriver(ardroneAdaptor, "drone") work := func() { detect := false drone.TakeOff() var image *cv.IplImage gobot.On(camera.Events["Frame"], func(data interface{}) { image = data.(*cv.IplImage) if detect == false { window.ShowImage(image) } }) gobot.On(drone.Events["Flying"], func(data interface{}) { gobot.After(1*time.Second, func() { drone.Up(0.2) }) gobot.After(2*time.Second, func() { drone.Hover() }) gobot.After(5*time.Second, func() { detect = true gobot.Every(300*time.Millisecond, func() { drone.Hover() i := image faces := opencv.DetectFaces(cascade, i) biggest := 0 var face *cv.Rect 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 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) }) gobot.After(20*time.Second, func() { drone.Land() }) }) }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("face", []gobot.Connection{ardroneAdaptor}, []gobot.Device{window, camera, drone}, work)) gbot.Start() }
func main() { gbot := gobot.NewGobot() window := opencv.NewWindowDriver("window") camera := opencv.NewCameraDriver("camera", 0) //e := edison.NewEdisonAdaptor("edison") //led1 := gpio.NewLedDriver(e, "led", "13") //firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") //led1 := gpio.NewLedDriver(firmataAdaptor, "led", "13") //motor := gpio.NewMotorDriver(firmataAdaptor, "motor", "4") //led2 := gpio.NewLedDriver(firmataAdaptor, "led", "10") //led3 := gpio.NewLedDriver(firmataAdaptor, "led", "9") _, currentfile, _, _ := runtime.Caller(0) work := func() { //speed := byte(0) //fadeAmount := byte(15) gobot.On(camera.Event("frame"), func(data interface{}) { cascade := cv.LoadHaarClassifierCascade(path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")) nestedcascade := cv.LoadHaarClassifierCascade(path.Join(path.Dir(currentfile), "smiled_04.xml")) i := data.(*cv.IplImage) faces := cascade.DetectObjects(i) teeth := 0 //flagcenter:= false for _, value := range faces { /*cv.Rectangle(i, cv.Point{value.X() + value.Width(), value.Y()}, cv.Point{value.X(), value.Y() + value.Height()}, cv.ScalarAll(255.0), 1, 0, 0)*/ mouths := nestedcascade.DetectObjects(i) for _, value1 := range mouths { if float64(value1.Y()) > float64(value.Y())+float64(value.Height())*3/5 && float64(value1.Y())+float64(value1.Height()) < float64(value.Y())+float64(value.Height()) && math.Abs((float64(value1.X())+float64(value1.Width())/2)-(float64(value.X())+float64(value.Width())/2)) < float64(value.Width())/10 { cv.Rectangle(i, cv.Point{value1.X() + value1.Width(), value1.Y()}, cv.Point{value1.X(), value1.Y() + value1.Height()}, cv.ScalarAll(255.0), 1, 0, 0) teeth = teeth + 1 //if value1.X()>240 && value1.Y()>240 && value1.Height()>50 && value1.Width()>100{ flagcenter=true }else{ flagcenter=false } fmt.Println(value1.X(), value1.Y(), value1.Height(), value1.Width()) } } //if len(smiles) > 0 { fmt.Println("worked")} } window.ShowImage(i) if teeth > 0 { //led1.On() //motor.Speed(speed) //speed = speed + fadeAmount //if speed == 0 || speed == 255 { // fadeAmount = -fadeAmount //} fmt.Println("good") //led2.On() //led3.On() /*f := faces[0] w := f.Width() fmt.Println(w) switch { case w < 250: fmt.Println("*") led2.On() led3.Off() //red3.Off() //red4.Off() //red5.Off() case w > 250 && w < 350: fmt.Println("**") led2.Off() led3.On() //red3.Off() //red4.Off() //red5.Off() case w > 350 && w < 400: fmt.Println("***") led2.On() led3.On() //red3.On() //red4.Off() //red5.Off() case w > 400 && w < 450: fmt.Println("****") led2.On() led3.On() //red3.On() //red4.On() //red5.Off() case w > 450: fmt.Println("*****") led2.Off() led3.Off() //red3.On() //red4.On() //red5.On() }*/ } else { //led1.Off() //speed = byte(0) //fadeAmount := byte(15) fmt.Println("smile please") //led2.Off() //led3.Off() //red3.Off() //red4.Off() //red5.Off() } }) } /*work1 := func() { gobot.Every(1*time.Second, func() { }) }*/ robot := gobot.NewRobot("cameraBot", //[]gobot.Connection{firmataAdaptor}, []gobot.Device{window, camera}, work, ) /*robot1 := gobot.NewRobot("ledBot", []gobot.Device{window,camera,led1}, work, )*/ gbot.AddRobot(robot) //gbot.AddRobot(robot1) gbot.Start() }