diff --git a/videoio.cpp b/videoio.cpp index 31d9e035..2fca2ac4 100644 --- a/videoio.cpp +++ b/videoio.cpp @@ -47,6 +47,10 @@ void VideoCapture_Grab(VideoCapture v, int skip) { } } +int VideoCapture_Retrieve(VideoCapture v, Mat buf) { + return v->retrieve(*buf); +} + // VideoWriter VideoWriter VideoWriter_New() { return new cv::VideoWriter(); diff --git a/videoio.go b/videoio.go index 940f1c8a..c9b319aa 100644 --- a/videoio.go +++ b/videoio.go @@ -379,6 +379,14 @@ func (v *VideoCapture) Grab(skip int) { C.VideoCapture_Grab(v.p, C.int(skip)) } +// Retrieve decodes and returns the grabbed video frame. Should be used after Grab +// +// For further details, please see: +// http://docs.opencv.org/master/d8/dfe/classcv_1_1VideoCapture.html#a9ac7f4b1cdfe624663478568486e6712 +func (v *VideoCapture) Retrieve(m *Mat) bool { + return C.VideoCapture_Retrieve(v.p, m.p) != 0 +} + // CodecString returns a string representation of FourCC bytes, i.e. the name of a codec func (v *VideoCapture) CodecString() string { res := "" diff --git a/videoio.h b/videoio.h index 7993d803..743c026f 100644 --- a/videoio.h +++ b/videoio.h @@ -28,6 +28,7 @@ double VideoCapture_Get(VideoCapture v, int prop); int VideoCapture_IsOpened(VideoCapture v); int VideoCapture_Read(VideoCapture v, Mat buf); void VideoCapture_Grab(VideoCapture v, int skip); +int VideoCapture_Retrieve(VideoCapture v, Mat buf); // VideoWriter VideoWriter VideoWriter_New(); diff --git a/videoio_test.go b/videoio_test.go index d01b238d..0a3501d6 100644 --- a/videoio_test.go +++ b/videoio_test.go @@ -199,3 +199,37 @@ func TestVideoWriterFile(t *testing.T) { t.Error("Invalid Write() in VideoWriter") } } + +func TestVideoCaptureFile_GrabRetrieve(t *testing.T) { + vc, err := VideoCaptureFile("images/small.mp4") + defer vc.Close() + + if err != nil { + t.Errorf("%s", err) + } + + if !vc.IsOpened() { + t.Error("Unable to open VideoCaptureFile") + } + + if fw := vc.Get(VideoCaptureFrameWidth); int(fw) != 560 { + t.Errorf("Expected frame width property of 560.0 got %f", fw) + } + if fh := vc.Get(VideoCaptureFrameHeight); int(fh) != 320 { + t.Errorf("Expected frame height property of 320.0 got %f", fh) + } + + vc.Set(VideoCaptureBrightness, 100.0) + + vc.Grab(10) + + img := NewMat() + defer img.Close() + + if ok := vc.Retrieve(&img); !ok { + t.Error("Unable to read VideoCaptureFile") + } + if img.Empty() { + t.Error("Unable to read VideoCaptureFile") + } +}