gobot.io/x/gobot/v2@v2.1.0/examples/opencv_window.go (about)

     1  //go:build example
     2  // +build example
     3  
     4  //
     5  // Do not build by default.
     6  
     7  package main
     8  
     9  import (
    10  	"gobot.io/x/gobot/v2"
    11  	"gobot.io/x/gobot/v2/platforms/opencv"
    12  	"gocv.io/x/gocv"
    13  )
    14  
    15  func main() {
    16  	window := opencv.NewWindowDriver()
    17  	camera := opencv.NewCameraDriver(0)
    18  
    19  	work := func() {
    20  		camera.On(opencv.Frame, func(data interface{}) {
    21  			img := data.(gocv.Mat)
    22  			window.ShowImage(img)
    23  			window.WaitKey(1)
    24  		})
    25  	}
    26  
    27  	robot := gobot.NewRobot("cameraBot",
    28  		[]gobot.Device{window, camera},
    29  		work,
    30  	)
    31  
    32  	robot.Start()
    33  }