简体   繁体   English

如何使用 Python 中的参数(第三个)参数调用 OpenCV VideoCapture()

[英]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).使用Z5BD4C87976F48E6AA53919D53E14025E9Z(4.5.4)在Z3D945423F8E94949496C429A5D8C65B465B4604FZ上Generally successful, but I do not know how to pass the third argument to the VideoCapture() call that has a C++ interface given as:一般成功,但我不知道如何将第三个参数传递给具有 C++ 接口的 VideoCapture() 调用,如下所示:

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

Specified here:此处指定:

OpenCV Video I/O VideoCapture class OpenCV 视频 I/O 视频捕捉 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.我尝试将第三个参数作为元组列表 [(a1,v1), (a2,v2)] 和字典 {a1:v1, a2:v2} 传递,但都不起作用。

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, ...) . params参数允许指定编码为对的额外参数(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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