0

enable OpenCV-Python compilation with OpenCV 3.2.0

With default CMakeLists.txt, we cannot compile OpenCV-Python with OpenCV 3.2.0 because
1. add_subdirectory() for python2 do not work appropriately
2. add_subdirectory() for python3 do not work appropriately
3. CMakeLists.txt in the root directory does not add python2/3 include directories.

So the solution is here. Let opencv-3.2.0_ROOT denote the root directory of OpenCV 3.2.0. We need to fix 3 files.

1. opencv-3.2.0_ROOT/modules/python/python2/CMakeLists.txt
#1 PYTHON2_INCLUDE_PATH -> PYTHON2_INCLUDE_DIR

2. opencv-3.2.0_ROOT/modules/python/python3/CMakeLists.txt
#1 PYTHON3_INCLUDE_PATH -> PYTHON3_INCLUDE_DIR

3. opencv-3.2.0_ROOT/CMakeLists.txt
add the following lines after #573
if(BUILD_opencv_python2)
ocv_include_directories(${PYTHON2_INCLUDE_DIR})
endif()
if(BUILD_opencv_python3)
ocv_include_directories(${PYTHON3_INCLUDE_DIR})
endif()

0

OpenCV 3.1.0 for Python2.7

 

  • PYTHON2_EXECUTABLE: /opt/anaconda/anaconda2/bin/python2.7
  • PYTHON2_INCLUDE_DIR: /opt/anaconda/anaconda2/include
  • PYTHON2_INCLUDE_DIR2:
  • PYTHON2_LIBRARY: /opt/anaconda/anaconda2/lib/libpython2.7.so
  • PYTHON2_LIBRARY_DEBUG:
  • PYTHON2_NUMPY_INCLUDE_DIRS: /opt/anaconda/anaconda2/lib/python2.7/site-packages/numpy/core/include
  • PYTHON2_PACKAGES_PATH: /opt/anaconda/anaconda2/lib/python2.7/site-packages
0

Notes on OpenCV-Python on Ubuntu

  • If PYTHON2_NUMPY_INCLUDE_DIRS is not found, python bindings for python2.7 is not generated.
  • Couldn’t compile with FFMPEG=ON. Turned off the flag.
  • BUILD_opencv_python2=ON
  • BUILD_opencv_python3=ON
  • OPENCV_EXTRA_MODULES_PATH=”CONTRIB_DIR/modules
  • With_QT=ON, otherwise OpenCV-Python cannot use highgui related functions.
  • Copy the following 3 files if c++ compilation outputs errors related to Qt
sudo ln -s /QT_CIR/5.6/gcc_64/lib/libicui18n.so.56 /usr/lib/x86_64-linux-gnu/libicui18n.so.56
sudo ln -s /QT_CIR/5.6/gcc_64/lib/libicuuc.so.56 /usr/lib/x86_64-linux-gnu/libicuuc.so.56
sudo ln -s /QT_CIR/5.6/gcc_64/lib/libicudata.so.56 /usr/lib/x86_64-linux-gnu/libicudata.so.56
0

highgui related issues of OpenCV-Python on Ubuntu 14.04

OpenCV-Python always crashed when I used highgui related functions. With Spyder, we can see only kernel crash, so I had no idea what happened. When I ran a problem from terminal, I got an error message that This application failed to start because it could not find or load the Qt platform plugin “xcb”. Googling so many things, I finally found out the solution. The problem was caused by Qt. OpenCV compilation used Qt5 while Anaconda installed Qt4. So, the solution is

conda remove qt
conda remove pyqt
conda install -c https://conda.anaconda.org/mmcauliffe pyqt5
conda install pyside
conda remove qt

The reason why I remove qt twice is installing pyside that is required for Spyder installes Qt4 again. Spyder actually requires PyQt4.X or PySide. I noticed that PySide can work even with Qt5.