简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM