Ask Your Question

Compile Python3 lib of OpenCV3.4.10

asked 2020-05-04 01:02:41 -0500

I am trying to compile the Python3 and Python 2 module for OpenCV in a Dockerfile on a Jetson Nano. Specifically, I want the cv2 files so I can use a command like import cv2 in a Python 3 script.

Although CMake finds a suitable version of Python 2 and 3:

[Build]   [main] -- Found PythonInterp: /usr/local/bin/python2.7 (found suitable version "2.7.17", minimum required is "2.7")
[Build]   [main] -- Found PythonLibs: /usr/local/lib/libpython2.7.a (found suitable exact version "2.7.17")
[Build]   [main] -- Found PythonInterp: /usr/local/bin/python3 (found suitable version "3.6.9", minimum required is "3.2")
[Build]   [main] -- Found PythonLibs: /usr/local/lib/libpython3.6m.a (found suitable exact version "3.6.9")

It appears to ignore it as far as creating the python install libraries:

[Build]   [main] --   Python 2:
[Build]   [main] --     Interpreter:                 /usr/local/bin/python2.7 (ver 2.7.17)
[Build]   [main] --     Libraries:                   NO
[Build]   [main] --     numpy:                       /usr/local/lib/python2.7/site-packages/numpy/core/include (ver 1.16.6)
[Build]   [main] --     install path:                -
[Build]   [main] --
[Build]   [main] --   Python 3:
[Build]   [main] --     Interpreter:                 /usr/local/bin/python3 (ver 3.6.9)
[Build]   [main] --     Libraries:                   NO
[Build]   [main] --     numpy:                       /usr/local/lib/python3.6/site-packages/numpy/core/include (ver 1.18.3)
[Build]   [main] --     install path:                -
[Build]   [main] --
[Build]   [main] --   Python (for build):            /usr/local/bin/python2.7

I've looked all over the web for days and days to try to solve, and have tried many variations in my cmake. Here is everything I've thrown at it:

/usr/src/app/cmake-3.17.2/build/bin/cmake -D WITH_CUDA=ON \
          -D CUDA_ARCH_BIN="5.3" \
          -D BUILD_LIST=cudev,highgui,videoio,video,cudaimgproc,ximgproc \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.10/modules \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D CMAKE_BUILD_TYPE=Release \
          -D PYTHON3_EXECUTABLE=$(which python3.6) \
          -D PYTHON2_EXECUTABLE=$(which python2.7) \
          -D PYTHON2_INCLUDE_DIR=$(python2.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
          -D PYTHON2_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/python2.7 \
          -D PYTHON3_INCLUDE_DIR=$(python3.6 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
          -D PYTHON3_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/python3.6m \
          -D PYTHON2_LIBRARY=/usr/lib/python2.7/config-aarch64-linux-gnu/ \
          -D PYTHON3_LIBRARY=/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu/ \
          -D PYTHON2_NUMPY_INCLUDE_DIR=$(python2.7 -c "import numpy; print(numpy.get_include())") \
          -D PYTHON3_NUMPY_INCLUDE_DIR=$(python3 -c "import numpy; print(numpy.get_include())") \
          -D BUILD_opencv_python3=ON \
          -D BUILD_opencv_python2=ON \
          -D HAVE_opencv_python2=ON \
          -D HAVE_opencv_python3=ON \
          -D PYTHON_DEFAULT_EXECUTABLE=$(which python2.7) \
          -D OPENCV_PYTHON3_INSTALL_PATH=/usr/src/app \
          -D BUILD_TESTS=OFF \
          -D \
          -D WITH_GSTREAMER=ON \
          -D WITH_GSTREAMER_0_10=OFF \
          -D WITH_CUDA=OFF \
          -D WITH_TBB=ON \
          -D WITH_LIBV4L=ON \
          -D WITH_FFMPEG=ON .. && make -j8 && make install

I've tried many combinations and permutations with no luck. Any suggestions would be appreciated!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-05-06 10:19:44 -0500

I finally found the answer buried in another question: "BUILD_LIST is acting like a white list function, only the ones specified will be built given their required ones (dependency) are specified too." So removing -D BUILD_LIST=cudev,highgui,videoio,video,cudaimgproc,ximgproc \ above builds Python and provides an install path.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-05-04 01:02:41 -0500

Seen: 65 times

Last updated: May 04