hybridgroup.gobot/platforms/opencv/window_driver.go

53 lines
1.2 KiB
Go
Raw Permalink Normal View History

2014-04-28 07:58:34 +08:00
package opencv
import (
cv "github.com/lazywei/go-opencv/opencv"
"gobot.io/x/gobot"
2014-04-28 07:58:34 +08:00
)
type window interface {
ShowImage(*cv.IplImage)
}
// 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 = cv.NewWindow(w.Name(), cv.CV_WINDOW_NORMAL)
},
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-04-28 07:58:34 +08:00
cv.StartWindowThread()
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
2014-04-28 07:58:34 +08:00
func (w *WindowDriver) ShowImage(image *cv.IplImage) {
w.window.ShowImage(image)
}