Skip to content

Instantly share code, notes, and snippets.

@Naville
Last active January 5, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naville/ea9c9b98709d88ce080edd0f6f190fcc to your computer and use it in GitHub Desktop.
Save Naville/ea9c9b98709d88ce080edd0f6f190fcc to your computer and use it in GitHub Desktop.
Compile OpenCV3 with opencv_contribution&&Python2&&Python3 Support

This is constructed with multiple tutorials online as well as opencv's issues

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/Development/opencv_contrib/modules -DPYTHON2_EXECUTABLE=$(which python2) -DPYTHON2_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")  -DPYTHON2_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DPYTHON2_PACKAGES_PATH=$(python -c "import site; print(site.getsitepackages()[-1])")  -DPYTHON3_EXECUTABLE=$(which python3)  -DPYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")  -DPYTHON3_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DPYTHON3_PACKAGES_PATH=$(python3 -c "import site; print(site.getsitepackages()[-1])") -DBUILD_opencv_python2=on -DBUILD_opencv_python3=on -DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DPYTHON_INCLUDE_DIRS=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_EXECUTABLE=$(which python3) ~/Development/opencv

This by default install for python3, for python2, change -DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DPYTHON_INCLUDE_DIRS=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_EXECUTABLE=$(which python3) 's python3 to python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment