My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Installation_OpenCV  
Instructions for installing OpenCV 2.x so that it is usable by PyOpenCV
Updated Sep 24, 2010 by pmtri80@gmail.com

Installing OpenCV 2.x

Willow Garage's pre-compiled OpenCV 2.x builds are in general not suitable for PyOpenCV. The reasons are mainly due to the use of manually written SSE+SSE2 code (see below) and "parallel mode" STL containers (only for OpenCV 2.0 with OpenMP enabled). It is likely that you require a new OpenCV 2.x build that is compiled from source. Do not worry though, you can still use your current OpenCV 2.x build (if any) in other applications. PyOpenCV always tries to load the build you have specified in the config.py file instead of other builds.

You have two options to obtain a usable OpenCV build for PyOpenCV: build OpenCV 2.x from source, or download a pre-compiled build.

Building OpenCV 2.x from source

If you have decided to build OpenCV 2.x from source, just use the standard cmake approach. However, take note of the followings:

  1. You should use GCC 4.x as the default C++ compiler. I have not tested PyOpenCV with other C++ compilers.
  2. Uncheck the BUILD_SWIG_PYTHON_SUPPORT option:
  3. This is important. When the SWIG option is set, the majority of new C++ member functions of various classes in the ML component are disabled in OpenCV's header file ml.h. PyOpenCV, however, relies on these C++ functions to interface with the classes. Therefore, not using SWIG is a must.
  4. Uncheck the BUILD_NEW_PYTHON_SUPPORT option:
  5. It appears that when the option is checked, the resultant OpenCV is somehow modified such that it could lead to a crash in PyOpenCV. The issue is still under investigation.
  6. Uncheck the USE_SSE/ENABLE_SSE option:
  7. Uncheck the USE_SSE2/ENABLE_SSE2 option:
  8. When either of these options are enabled, along with SIMP code automatically generated by the compiler, some manually written SIMP code is used. However, with no offence to the Willow Garage people, it appears that the manually written code crashes when being invoked from a Python extension. Therefore, the safest best for now is to uncheck these options. For the record, the C++ wrapping code of PyOpenCV can be built safely with -msse -msse2 -mfpmath=sse -mtune=generic flags set.
  9. If you want to enable OpenMP when building OpenCV 2.0:
  10. Before running cmake, edit file CMakeLists.txt, search for "-D_GLIBCXX_PARALLEL" and remove it. Basically, when this option is set, experimental "parallel mode" STL containers are used, which are incompatible with the standard "normal mode" STL containers used by Boost.Python and other libraries. Of course, if you could recompile every single library that is connected to OpenCV with option "-D_GLIBCXX_PARALLEL" set, then it would be another matter.
  11. On Windows: enabling the VideoInput library:
  12. The libvideoInput.a library file that comes with OpenCV was built using the old SJLJ exception handling method. Hence, you can only link against it by using a compiler that uses SJLJ. To link against it using a compiler that uses the DWARF-2 exception handling method, replace the libvideoInput.a file in OpenCV with this file. In addition, search in file src/highgui/CMakeLists.txt for the following text: "videoInput strmiids". It should be at somewhere near line 199. Then, insert " ole32 oleaut32 uuid" right after the text, i.e. "videoInput strmiids ole32 oleaut32 uuid". The developers have forgotten to insert these Windows libraries.

Downloading a pre-compiled OpenCV 2.x build

In some cases, there is a faster and trouble-free way to install OpenCV 2.x that is suitable for PyOpenCV. Just go to the Downloads page, download a pre-compiled OpenCV 2.x suitable for your platform, and follow the instructions inside the file to install. I have gone through most of the troubles that could have happened to build them. You do not have to go through the same pain.

Comment by sheehy.j...@gmail.com, Feb 18, 2011

what if I am using 64-Bit windows? will win32 still work sheehy.john@gmail.com


Sign in to add a comment
Powered by Google Project Hosting