Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

videoio: add Retrieve function #1133

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}
Loading