hybridgroup.gobot/platforms/opencv/window_driver.go

57 lines
1.3 KiB
Go
Raw Permalink Normal View History

2014-04-28 07:58:34 +08:00
package opencv
import (
"gobot.io/x/gobot"
"gocv.io/x/gocv"
2014-04-28 07:58:34 +08:00
)
type window interface {
IMShow(gocv.Mat)
}
// WindowDriver is the Gobot Driver for the OpenCV window
2014-04-28 07:58:34 +08:00
type WindowDriver struct {
name string
2014-07-24 07:54:39 +08:00
window window
start func(*WindowDriver)
2014-04-28 07:58:34 +08:00
}
// NewWindowDriver creates a new window driver.
// It adds an start function to initialize window
func NewWindowDriver() *WindowDriver {
2014-05-23 11:53:15 +08:00
return &WindowDriver{
name: "Window",
2014-07-24 07:54:39 +08:00
start: func(w *WindowDriver) {
w.window = gocv.NewWindow(w.Name())
2014-07-24 07:54:39 +08:00
},
2014-05-23 11:53:15 +08:00
}
2014-04-28 07:58:34 +08:00
}
// Name returns the Driver name
func (w *WindowDriver) Name() string { return w.name }
// SetName sets the Driver name
func (w *WindowDriver) SetName(n string) { w.name = n }
// Connection returns the Driver's connection
func (w *WindowDriver) Connection() gobot.Connection { return nil }
// Start starts window thread and driver
func (w *WindowDriver) Start() (err error) {
2014-07-24 07:54:39 +08:00
w.start(w)
return
2014-04-28 07:58:34 +08:00
}
// Halt returns true if camera is halted successfully
func (w *WindowDriver) Halt() (err error) { return }
2014-04-28 07:58:34 +08:00
// ShowImage displays image in window
func (w *WindowDriver) ShowImage(img gocv.Mat) {
w.window.IMShow(img)
}
// WaitKey gives window a chance to redraw, and checks for keyboard input
func (w *WindowDriver) WaitKey(pause int) int {
return gocv.WaitKey(pause)
2014-04-28 07:58:34 +08:00
}