mirror of
https://github.com/gen2brain/cam2ip.git
synced 2025-12-16 04:18:39 +00:00
Reuse frame
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user