2014-04-28 07:58:34 +08:00
|
|
|
package opencv
|
|
|
|
|
|
|
|
import (
|
2016-08-27 17:56:01 +08:00
|
|
|
cv "github.com/lazywei/go-opencv/opencv"
|
2017-03-28 02:10:37 +08:00
|
|
|
"gobot.io/x/gobot"
|
2014-04-28 07:58:34 +08:00
|
|
|
)
|
|
|
|
|
2014-12-23 06:24:06 +08:00
|
|
|
type window interface {
|
|
|
|
ShowImage(*cv.IplImage)
|
|
|
|
}
|
|
|
|
|
2016-12-01 21:58:58 +08:00
|
|
|
// WindowDriver is the Gobot Driver for the OpenCV window
|
2014-04-28 07:58:34 +08:00
|
|
|
type WindowDriver struct {
|
2014-11-29 10:05:19 +08:00
|
|
|
name string
|
2014-07-24 07:54:39 +08:00
|
|
|
window window
|
|
|
|
start func(*WindowDriver)
|
2014-04-28 07:58:34 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 23:53:39 +08:00
|
|
|
// NewWindowDriver creates a new window driver.
|
2014-10-21 00:23:33 +08:00
|
|
|
// It adds an start function to initialize window
|
2016-10-01 23:53:39 +08:00
|
|
|
func NewWindowDriver() *WindowDriver {
|
2014-05-23 11:53:15 +08:00
|
|
|
return &WindowDriver{
|
2016-10-01 23:53:39 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-01 21:58:58 +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
|
2014-11-29 10:05:19 +08:00
|
|
|
func (w *WindowDriver) Connection() gobot.Connection { return nil }
|
|
|
|
|
2014-10-21 00:23:33 +08:00
|
|
|
// Start starts window thread and driver
|
2016-11-08 03:06:55 +08:00
|
|
|
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)
|
2014-11-20 15:21:19 +08:00
|
|
|
return
|
2014-04-28 07:58:34 +08:00
|
|
|
}
|
|
|
|
|
2014-10-21 00:23:33 +08:00
|
|
|
// Halt returns true if camera is halted successfully
|
2016-11-08 03:06:55 +08:00
|
|
|
func (w *WindowDriver) Halt() (err error) { return }
|
2014-04-28 07:58:34 +08:00
|
|
|
|
2014-10-21 00:23:33 +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)
|
|
|
|
}
|