Reuse frame

This commit is contained in:
Milan Nikolic
2018-03-14 14:33:01 +01:00
parent 3c0c949f31
commit e1f03b55a1
4 changed files with 22 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ import (
// Camera represents camera.
type Camera struct {
camera *opencv.Capture
frame *opencv.IplImage
}
// New returns new Camera for given camera index.
@@ -30,8 +31,8 @@ func New(index int) (camera *Camera, err error) {
// Read reads next frame from camera and returns image.
func (c *Camera) Read() (img image.Image, err error) {
if c.camera.GrabFrame() {
frame := c.camera.RetrieveFrame(1)
img = frame.ToImage()
c.frame = c.camera.RetrieveFrame(1)
img = c.frame.ToImage()
} else {
err = fmt.Errorf("camera: can not grab frame")
}
@@ -56,6 +57,7 @@ func (c *Camera) Close() (err error) {
return
}
c.frame.Release()
c.camera.Release()
c.camera = nil
return