Skip to content

Commit

Permalink
videoio: add Retrieve function
Browse files Browse the repository at this point in the history
  • Loading branch information
AnteWall authored and deadprogram committed Mar 30, 2024
1 parent f1e5e40 commit 0f64f63
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions videoio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions videoio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down
1 change: 1 addition & 0 deletions videoio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
34 changes: 34 additions & 0 deletions videoio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 0f64f63

Please sign in to comment.