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 PYTHON2_INCLUDE_PATH -> PYTHON2_INCLUDE_DIR
#1 PYTHON3_INCLUDE_PATH -> PYTHON3_INCLUDE_DIR
add the following lines after #573
OpenCV flags have a little bit different names when using with python. The name CV_FLAGNAME is set as cv2.FLAGNAME. For instance, CV_CALIB_CB_ADAPTIVE_THRESH is defined as cv2.CALIB_CB_ADAPTIVE_THRESH.
Please use OpenCV 3.1.0 prebuilt binary provided at github, not at sourceforge. The one provided at sourceforge has some problem. Double clicking the exe file, I got an error message saying that can not open file “***/opencv-3.1.0.exe” as an archive.
- 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.
- 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
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.