简体   繁体   English

视频捕获openCV中的PROPID参数

[英]Video capture PROPID parameters in openCV

I am using Python 3.4 and opencv(64 bits). 我使用的是Python 3.4和opencv(64位)。 My question is about property identifier parameters such as CV_CAP_PROP_FRAME_WIDTH, or CV_CAP_PROP_FRAME_HEIGHT for video capture. 我的问题是关于属性标识符参数,例如用于视频捕获的CV_CAP_PROP_FRAME_WIDTH或CV_CAP_PROP_FRAME_HEIGHT。 The full documentation for this is here: http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=get#cv2.VideoCapture.get . 完整的文档在这里: http//docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=get#cv2.VideoCapture.get My program works fine when I hard code these numbers in but it does not recognize any of the terms given in the documentation. 当我对这些数字进行硬编码时,我的程序运行正常,但它无法识别文档中给出的任何术语。 I read some earlier posts that these were available in cv but are not available in cv2 library. 我读过一些早期的帖子,这些帖子在cv中可用,但在cv2库中不可用。 Has there been any updates? 有没有更新? I can not find anything else here... I don't like using hard-coded numbers. 我在这里找不到任何其他东西......我不喜欢使用硬编码的数字。 Any advice? 有什么建议? Thanks in advance. 提前致谢。

I stumbled upon the properties while looking through related posts on the internet. 我在浏览互联网上的相关帖子时偶然发现了这些房产。

For Python OpenCV 3, they are directly in cv2 module but have to be accessed without the leading CV_ . 对于Python OpenCV 3,它们直接在cv2模块中,但必须在没有前导CV_情况下进行访问。 For example the two properties you mentioned can be accessed as: 例如,您提到的两个属性可以访问为:

cv2.CAP_PROP_FRAME_WIDTH
cv2.CAP_PROP_FRAME_HEIGHT

A working example would be: 一个工作的例子是:

import numpy
import cv2

cap = cv2.VideoCapture("examplevid.mp4")
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
width  = cap.get(cv2.CAP_PROP_FRAME_WIDTH)

Note that this only applies to OpenCV 3. For older versions of OpenCV (ie 2.XX) the cv2.cv.CV_CAP_PROP_FRAME_HEIGHT syntax should work. 请注意,这仅适用于OpenCV 3.对于旧版本的OpenCV(即cv2.cv.CV_CAP_PROP_FRAME_HEIGHT ), cv2.cv.CV_CAP_PROP_FRAME_HEIGHT语法应该有效。

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

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