Getting movie properties with python and opencv
The CV_CAP_PROP_*
constants can be accessed from the cv2.cv
module:
cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
Unfortunately, not all useful things have been ported from cv2
from cv
so it is generally a good idea to look in cv2.cv
if you can't find what you are looking for in cv2
.
Some constants, like cv2.CV_LOAD_IMAGE_*
have been moved, for example.
UPDATE:- For OpenCV 3.1 use:-
cap.get(cv2.CAP_PROP_FRAME_COUNT)
Basically, the property name has been modified and the "CV_" in the beginning is no longer required. (Credits to Blane in the answers section)
I am using OpenCV 3.1 and the above methods suggested by Hannes do not work for me. It seems that the method call and name formatting of properties have been slightly updated for OpenCV 3.1. For example, cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
returns AttributeError: 'module' object has no attribute 'cv'
with OpenCV 3.1. The following minor adjustment to the code worked for me:
cap.get(cv2.CAP_PROP_FRAME_WIDTH)
Note that CV_ is no longer necessary as a prefix for the attribute name.