hybridgroup.gobot/platforms/opencv/window_driver.go

46 lines
1.0 KiB
Go
Raw Normal View History

2014-04-28 07:58:34 +08:00
package opencv
import (
"github.com/hybridgroup/gobot"
cv "github.com/lazywei/go-opencv/opencv"
2014-04-28 07:58:34 +08:00
)
type window interface {
ShowImage(*cv.IplImage)
}
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 with specified name.
// It adds an start function to initialize window
2014-05-23 11:53:15 +08:00
func NewWindowDriver(name string) *WindowDriver {
return &WindowDriver{
name: name,
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
}
func (w *WindowDriver) Name() string { return w.name }
func (w *WindowDriver) Connection() gobot.Connection { return nil }
// Start starts window thread and driver
func (w *WindowDriver) Start() (errs []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() (errs []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)
}