How do I get PROPID video capture constants to work?

asked 2015-09-09 15:29:45 -0500

MXN gravatar image

updated 2015-09-10 17:56:24 -0500

I am new to python and openCV. I am using Python 3.4 and opencv(64 bits). My question is about property identifier constants such as CV_CAP_PROP_FRAME_WIDTH, or CV_CAP_PROP_FRAME_HEIGHT for video capture. The full documentation for this is here: 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. I have the same problem with cv2.namedWindow flags like CV_WINDOW_NORMAL. I read that I must have import as cv but I get this error: ImportError: No module named ''; 'cv2' is not a package.

Any advice? Thanks in advance.

edit retag flag offensive close merge delete


is that opencv3 ? (the old module indeed got removed)

try a >>> help(cv2) , you will find all the constants at the end of that (very long) list.

they dropped the CV_ prefix from most constants, that's all.

berak gravatar imageberak ( 2015-09-10 01:06:08 -0500 )edit

Thanks for the feedback. Yes it is opencv3. I can see that the the CV_ prefixes have been dropped when I type >>> help (cv2) but my program still does not recognize the constants even without the CV_. Here is simple code:

print (cap.get(CAP_PROP_FRAME_WIDTH))

and I get this error: NameError: name 'CAP_PROP_FRAME_WIDTH' is not defined

At the top of the program I have import cv2. Do I need to import anything else?

MXN gravatar imageMXN ( 2015-09-10 16:53:40 -0500 )edit

Even at the command prompt I import cv2 but cannot access the constants. I cannot print the numerical value of the constants. I get: NameError: name 'CAP_PROP_FRAME_WIDTH' is not defined.

MXN gravatar imageMXN ( 2015-09-10 17:03:32 -0500 )edit


berak gravatar imageberak ( 2015-09-10 22:53:46 -0500 )edit

Thank you much. It worked.

MXN gravatar imageMXN ( 2015-09-11 13:53:19 -0500 )edit