How to use OpenCV constants in Python

OpenCV has a Python API. The Python function calls are well documented and listed along with the C and C++ calls. However, it is not obvious how to use the various OpenCV constants and enums in Python. These are typically named as CV_SOME_THING. For example: CV_WINDOW_AUTOSIZE.

  • A few of these named constants seem to be available for use in Python by importing the cv package. For example:
import cv
win = cv.NamedWindow("haha", cv.CV_WINDOW_AUTOSIZE)
  • However, I find that many of these named constants are not available in Python. You will need to look up their integer value from OpenCV header files and pass those raw integer values directly to the calls.

Here is a list of integer values for OpenCV constants that I frequently need to use:


Tried with: OpenCV 2.4.9, Python 2.7.3 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s