1

Using OpenCV (4.5.4) on Ubuntu (Ubuntu Server 20.04.3 LTS (RPi 2/3/4/400) / 32-bit) in Python (3.9.7). Generally successful, but I do not know how to pass the third argument to the VideoCapture() call that has a C++ interface given as:

cv::VideoCapture::VideoCapture (
   const String & filename,
   int apiPreference,
   const std::vector< int > & params 
)   

Specified here:

OpenCV Video I/O VideoCapture class

Current code looks like:

import cv2
cap = cv2.VideoCapture('/dev/video0', cv2.CAP_FFMPEG)

Which works fine, but I want to pass the third argument to the call so that I can set video parameters. I've tried passing the third argument as a list of tuples [(a1,v1), (a2,v2)] and as a dict {a1:v1, a2:v2} but neither works.

I can't find any examples in a lot of searching...

1 Answer 1

1

Try like this:

cap = cv2.VideoCapture('/dev/video0', cv2.CAP_FFMPEG, (a1, v1, a2, v2))

Here's the relevant bit from the docs you linked:

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I had tried that but convinced myself it was not working. It does in fact seem to pass the parameters to the call. Remaining problem is that I still cannot properly open the capture device using FFMPEG UNLESS I set environment variables like this: export OPENCV_FFMPEG_CAPTURE_OPTIONS="input_format;rawvideo|video_size;640x480". Then all is well, but that really defeats the purpose of passing in video parameters as above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.