opencv: read the image frames as fast as possible
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
4cdf00c4d3
commit
5f40f44269
|
@ -3,8 +3,6 @@ package opencv
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gocv"
|
||||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
@ -20,22 +18,20 @@ const (
|
|||
|
||||
// CameraDriver is the Gobot Driver for the OpenCV camera
|
||||
type CameraDriver struct {
|
||||
name string
|
||||
camera capture
|
||||
interval time.Duration
|
||||
Source interface{}
|
||||
start func(*CameraDriver) (err error)
|
||||
name string
|
||||
camera capture
|
||||
Source interface{}
|
||||
start func(*CameraDriver) (err error)
|
||||
gobot.Eventer
|
||||
}
|
||||
|
||||
// NewCameraDriver creates a new driver with specified source.
|
||||
// It also creates a start function to either set camera as a File or Camera capture.
|
||||
func NewCameraDriver(source interface{}, v ...time.Duration) *CameraDriver {
|
||||
func NewCameraDriver(source interface{}) *CameraDriver {
|
||||
c := &CameraDriver{
|
||||
name: "Camera",
|
||||
Eventer: gobot.NewEventer(),
|
||||
Source: source,
|
||||
interval: 10 * time.Millisecond,
|
||||
name: "Camera",
|
||||
Eventer: gobot.NewEventer(),
|
||||
Source: source,
|
||||
start: func(c *CameraDriver) (err error) {
|
||||
switch v := c.Source.(type) {
|
||||
case string:
|
||||
|
@ -49,10 +45,6 @@ func NewCameraDriver(source interface{}, v ...time.Duration) *CameraDriver {
|
|||
},
|
||||
}
|
||||
|
||||
if len(v) > 0 {
|
||||
c.interval = v[0]
|
||||
}
|
||||
|
||||
c.AddEvent(Frame)
|
||||
|
||||
return c
|
||||
|
@ -67,8 +59,7 @@ func (c *CameraDriver) SetName(n string) { c.name = n }
|
|||
// Connection returns the Driver's connection
|
||||
func (c *CameraDriver) Connection() gobot.Connection { return nil }
|
||||
|
||||
// Start initializes camera by grabbing a frame
|
||||
// every `interval` and publishing an frame event
|
||||
// Start initializes camera by grabbing frames
|
||||
func (c *CameraDriver) Start() (err error) {
|
||||
if err := c.start(c); err != nil {
|
||||
return err
|
||||
|
@ -79,7 +70,6 @@ func (c *CameraDriver) Start() (err error) {
|
|||
if ok := c.camera.Read(img); ok {
|
||||
c.Publish(Frame, img)
|
||||
}
|
||||
time.Sleep(c.interval)
|
||||
}
|
||||
}()
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue