Update opencv package and examples
This commit is contained in:
parent
89b781fbdb
commit
cfc11f8eda
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
cv "github.com/hybridgroup/go-opencv/opencv"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/opencv"
|
||||
"github.com/hybridgroup/gobot/platform/opencv"
|
||||
"path"
|
||||
"runtime"
|
||||
)
|
||||
|
@ -12,11 +12,10 @@ func main() {
|
|||
_, currentfile, _, _ := runtime.Caller(0)
|
||||
cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
|
||||
|
||||
window := opencv.NewWindowDriver()
|
||||
window.Name = "window"
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
camera := opencv.NewCameraDriver()
|
||||
camera.Name = "camera"
|
||||
window := opencv.NewWindowDriver("window")
|
||||
camera := opencv.NewCameraDriver("camera", 0)
|
||||
|
||||
work := func() {
|
||||
var image *cv.IplImage
|
||||
|
@ -36,11 +35,8 @@ func main() {
|
|||
}()
|
||||
}
|
||||
|
||||
robot := gobot.Robot{
|
||||
Connections: []gobot.Connection{},
|
||||
Devices: []gobot.Device{window, camera},
|
||||
Work: work,
|
||||
}
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("faceBot", []gobot.Connection{}, []gobot.Device{window, camera}, work))
|
||||
|
||||
robot.Start()
|
||||
gbot.Start()
|
||||
}
|
||||
|
|
|
@ -3,16 +3,14 @@ package main
|
|||
import (
|
||||
cv "github.com/hybridgroup/go-opencv/opencv"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/opencv"
|
||||
"github.com/hybridgroup/gobot/platforms/opencv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
window := opencv.NewWindowDriver()
|
||||
window.Name = "window"
|
||||
|
||||
camera := opencv.NewCameraDriver()
|
||||
camera.Name = "camera"
|
||||
window := opencv.NewWindowDriver("window")
|
||||
camera := opencv.NewCameraDriver("camera", 0)
|
||||
|
||||
work := func() {
|
||||
gobot.On(camera.Events["Frame"], func(data interface{}) {
|
||||
|
@ -20,11 +18,8 @@ func main() {
|
|||
})
|
||||
}
|
||||
|
||||
robot := gobot.Robot{
|
||||
Connections: []gobot.Connection{},
|
||||
Devices: []gobot.Device{window, camera},
|
||||
Work: work,
|
||||
}
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("cameraBot", []gobot.Connection{}, []gobot.Device{window, camera}, work))
|
||||
|
||||
robot.Start()
|
||||
gbot.Start()}
|
||||
}
|
||||
|
|
|
@ -8,26 +8,32 @@ import (
|
|||
type CameraDriver struct {
|
||||
gobot.Driver
|
||||
camera *cv.Capture
|
||||
Source string
|
||||
Source interface{}
|
||||
}
|
||||
|
||||
func NewCameraDriver() *CameraDriver {
|
||||
func NewCameraDriver(name string, source interface{}) *CameraDriver {
|
||||
return &CameraDriver{
|
||||
Driver: gobot.Driver{
|
||||
Name: name,
|
||||
Commands: []string{},
|
||||
Events: map[string]chan interface{}{
|
||||
"Frame": make(chan interface{}, 0),
|
||||
},
|
||||
},
|
||||
Source: source,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CameraDriver) Start() bool {
|
||||
if c.Source != "" {
|
||||
c.camera = cv.NewFileCapture(c.Source)
|
||||
} else {
|
||||
c.camera = cv.NewCameraCapture(0)
|
||||
switch v := c.Source.(type) {
|
||||
case string:
|
||||
c.camera = cv.NewFileCapture(v)
|
||||
case int:
|
||||
c.camera = cv.NewCameraCapture(v)
|
||||
default:
|
||||
panic("unknown camera source")
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
if c.camera.GrabFrame() {
|
||||
|
|
|
@ -11,7 +11,7 @@ var _ = Describe("Camera", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
c = NewCameraDriver()
|
||||
c = NewCameraDriver("bot", 0)
|
||||
})
|
||||
|
||||
PIt("Must be able to Start", func() {
|
||||
|
|
|
@ -10,8 +10,12 @@ type WindowDriver struct {
|
|||
window *cv.Window
|
||||
}
|
||||
|
||||
func NewWindowDriver() *WindowDriver {
|
||||
return &WindowDriver{}
|
||||
func NewWindowDriver(name string) *WindowDriver {
|
||||
return &WindowDriver{
|
||||
Driver: gobot.Driver{
|
||||
Name: name,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WindowDriver) Start() bool {
|
||||
|
|
|
@ -11,7 +11,7 @@ var _ = Describe("Window", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
w = NewWindowDriver()
|
||||
w = NewWindowDriver("bot")
|
||||
})
|
||||
|
||||
PIt("Must be able to Start", func() {
|
||||
|
|
Loading…
Reference in New Issue