I had the same issue with generating Python 2.7 bindings. Found the solution by manually inspecting opencv/CMakeLists.txt
file. I think transposing the variables for Python 3 may solve your issue.
Symptom
Before you start building opencv, you can already tell whether you will get the python binding file cv2.so
by examining the cmake command output at lines containing To be built
or Unavailable
. In my case I had:
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern hdf java matlab ovis python2 python3 sfm viz
Notice how python2
and python3
show up as unavailable right away at the end.
Fix (adapt python2 references for python3 if needed)
In CMakeLists.txt
there's a line containing
BUILD_opencv_python2
Next to it are a bunch of lines that generate the output of the cmake command. They are helpful as they inform about which variables cmake expects. In particular, the references to numpy are mandatory to build the python bindings. From these lines, I learned that for opencv 3.4.1, I had to invoke cmake using:
-D PYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include
-D PYTHON2_NUMPY_VERSION=1.12.1
I can see from your command that you use the deprecated BUILD_NEW_PYTHON_SUPPORT
flag. For opencv 3.4 the flag names have changed, and according to the content of CMakeLists.txt
the new variable name is:
-D BUILD_opencv_python3=ON
I also read in another SO comment that cv2.so
won't be generated without the following flag (untested):
-D BUILD_EXAMPLES=ON
TL;DR
Edits to your command:
- Remove:
-D BUILD_NEW_PYTHON_SUPPORT=ON
- Add:
-D BUILD_opencv_python3=ON -D BUILD_EXAMPLES=ON -D PYTHON3_NUMPY_INCLUDE_DIRS=<path_to_numpy>/core/include -D PYTHON2_NUMPY_VERSION=<your_numpy_version>