import getpass import os import pathlib import sys import sh BASE_DIR = os.path.abspath(os.path.join(__file__, '..')) OPENCV_VERSION = '4.5.2' def build_opencv(): python_path = pathlib.Path(sh.pyenv.which('python').stdout.decode()).parent.parent version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) # make build directory build_dir = os.path.join(BASE_DIR, "opencv-{}".format(OPENCV_VERSION), 'build') pathlib.Path(build_dir).mkdir(parents=True, exist_ok=True) os.chdir(build_dir) sh.cmake( "..", "-DCMAKE_BUILD_TYPE=RELEASE", "-DCMAKE_INSTALL_PREFIX={}/.local".format(pathlib.Path.home()), "-DWITH_MKL=OFF", "-DWITH_CUDA=OFF", #"-DWITH_FFMPEG=OFF", "-DINSTALL_C_EXAMPLES=OFF", "-DBUILD_opencv_legacy=OFF", "-DPYTHON_DEFAULT_EXECUTABLE={}/bin/python".format(python_path), "-DBUILD_NEW_PYTHON_SUPPORT=ON", "-DBUILD_opencv_python2=OFF", "-DBUILD_opencv_python3=ON", "-DOPENCV_EXTRA_MODULES_PATH={}/opencv_contrib-{}/modules".format(BASE_DIR, OPENCV_VERSION), "-DPYTHON_EXECUTABLE={}/bin/python".format(python_path), "-DPYTHON3_LIBRARY={}/lib/libpython{}.a".format(python_path, version), "-DPYTHON3_INCLUDE_DIR={}/include/python{}".format(python_path, version), "-DPYTHON3_PACKAGES_PATH={}/lib/python{}/site-packages/".format(python_path, version), "-DPYTHON3_NUMPY_INCLUDE_DIRS={}/lib/python{}/site-packages/numpy/core/include".format(python_path, version), "-DBUILD_EXAMPLES=OFF", "-DBUILD_TESTS=OFF", "-DBUILD_PERF_TESTS=OFF", _out=sys.stdout, ) if __name__ == "__main__": build_opencv()