简体   繁体   中英

Video capture PROPID parameters in openCV

I am using Python 3.4 and opencv(64 bits). My question is about property identifier parameters such as CV_CAP_PROP_FRAME_WIDTH, or CV_CAP_PROP_FRAME_HEIGHT for video capture. 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 . 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. 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_ . 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.

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