2014-04-28 07:58:34 +08:00
|
|
|
package opencv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hybridgroup/gobot"
|
2016-08-27 17:56:01 +08:00
|
|
|
cv "github.com/lazywei/go-opencv/opencv"
|
2014-04-28 07:58:34 +08:00
|
|
|
)
|
|
|
|
|
2014-12-23 06:24:06 +08:00
|
|
|
type window interface {
|
|
|
|
ShowImage(*cv.IplImage)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-21 00:23:33 +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{
|
2014-11-29 10:05:19 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-29 10:05:19 +08:00
|
|
|
func (w *WindowDriver) Name() string { return w.name }
|
|
|
|
func (w *WindowDriver) Connection() gobot.Connection { return nil }
|
|
|
|
|
2014-10-21 00:23:33 +08:00
|
|
|
// Start starts window thread and driver
|
2014-11-20 15:21:19 +08:00
|
|
|
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)
|
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
|
2014-11-20 15:21:19 +08:00
|
|
|
func (w *WindowDriver) Halt() (errs []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)
|
|
|
|
}
|