The constant CAP_PROP_FRAME_COUNT is missing in opencv `cv2` python module

How to access CAP_PROP_FRAME_COUNT from opencv in python? I tried this:

 import cv2 cap = cv2.VideoCapture('myvideo.avi') frames_count, fps, width, height = cap.get(cv2.CAP_PROP_FRAME_COUNT), cap.get(cv2.CAP_PROP_FPS), cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT) 

And this:

 import cv2 import cv cap = cv2.VideoCapture('myvideo.avi') frames_count, fps, width, height = cap.get(cv.CAP_PROP_FRAME_COUNT), cap.get(cv.CAP_PROP_FPS), cap.get(cv.CAP_PROP_FRAME_WIDTH), cap.get(cv.CAP_PROP_FRAME_HEIGHT) 

as well as this:

 import cv2 cap = cv2.VideoCapture('myvideo.avi') frames_count, fps, width, height = cap.get(cv2.cv.CAP_PROP_FRAME_COUNT), cap.get(cv2.cv.CAP_PROP_FPS), cap.get(cv2.cv.CAP_PROP_FRAME_WIDTH), cap.get(cv2.cv.CAP_PROP_FRAME_HEIGHT) 

But I get this error:

 AttributeError: 'module' object has no attribute 'CAP_PROP_FRAME_COUNT' 

I am using python 2.7.5 and OpenCV 2.4.9 .

+5
source share
4 answers

Constants in the first version of the python OpenCV module have the CV_ prefix. So you can use cv.CV_CAP_PROP_FRAME_COUNT or cv2.cv.CV_CAP_PROP_FRAME_COUNT .

+12
source

When running macports on OSX (opencv @ 3.0.0_1 + python27 + tbb)

You can get CAP_PROP_FRAME_HEIGHT and CAP_PROP_FRAME_WIDTH with the following:

 #!/opt/local/bin/python import cv2 vcap = cv2.VideoCapture() # set frame width and height vcap.set(cv2.CAP_PROP_FRAME_WIDTH, 480) vcap.set(cv2.CAP_PROP_FRAME_HEIGHT, 640) vcap.open(0) 
+9
source

http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get

 #3. CV_CAP_PROP_FRAME_WIDTH print "\t CAP_PROP_FRAME_WIDTH: ",cap.get(3) #4. CV_CAP_PROP_FRAME_HEIGHT print "\t CAP_PROP_FRAME_HEIGHT: ",cap.get(4) 

http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set

 #3. CV_CAP_PROP_FRAME_WIDTH cap.set(3,320) #4. CV_CAP_PROP_FRAME_HEIGHT cap.set(4,240) 
+2
source
 import cv2 import cv2.cv as cv 

Using cv2:

 stream = cv2.VideoCapture(filename) print stream.get(cv.CV_CAP_PROP_FRAME_COUNT) 
-1
source

Source: https://habr.com/ru/post/1205484/


All Articles