Update opencv package and examples

This commit is contained in:
Adrian Zankich 2014-05-22 20:53:15 -07:00
parent 89b781fbdb
commit cfc11f8eda
6 changed files with 34 additions and 33 deletions

View File

@ -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()
}

View File

@ -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()}
}

View File

@ -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() {

View File

@ -11,7 +11,7 @@ var _ = Describe("Camera", func() {
)
BeforeEach(func() {
c = NewCameraDriver()
c = NewCameraDriver("bot", 0)
})
PIt("Must be able to Start", func() {

View File

@ -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 {

View File

@ -11,7 +11,7 @@ var _ = Describe("Window", func() {
)
BeforeEach(func() {
w = NewWindowDriver()
w = NewWindowDriver("bot")
})
PIt("Must be able to Start", func() {