Home > Blockchain >  How to call OpenCV VideoCapture() with params (third) argument in Python
How to call OpenCV VideoCapture() with params (third) argument in Python

Time:12-08

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...

CodePudding user response:

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, ...).

  • Related