Skip to content

Latest commit

 

History

History
61 lines (37 loc) · 5.68 KB

compile.md

File metadata and controls

61 lines (37 loc) · 5.68 KB

Compile OpenCV

OpenCV 3.1

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_CXX_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=ON -DWITH_OPENGL=ON -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_TIFF=ON -DWITH_OPENEXR=ON -DWITH_PVAPI=ON -DWITH_UNICAP=OFF -DWITH_EIGEN=ON -DWITH_XINE=OFF -DBUILD_TESTS=ON -DCMAKE_SKIP_RPATH=ON -DWITH_CUDA=ON -DENABLE_SSE=ON -DENABLE_SSE2=ON -DENABLE_SSE3=ON -DWITH_TBB=ON -DWITH_1394=ON -DWITH_V4L=ON -DPYTHON_LIBRARIES=ON ..

OpenCV 3.2

Run:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_CXX_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_OPENGL=ON -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_TIFF=ON -DWITH_OPENEXR=ON -DWITH_PVAPI=ON -DWITH_UNICAP=OFF -DWITH_EIGEN=ON -DWITH_XINE=OFF -DBUILD_TESTS=ON -DCMAKE_SKIP_RPATH=ON -DWITH_CUDA=ON -DENABLE_SSE=ON -DENABLE_SSE2=ON -DENABLE_SSE3=ON -DWITH_TBB=ON -DWITH_1394=OFF -DWITH_V4L=ON -DPYTHON_LIBRARIES=ON -DWITH_VTK=ON -DWITH_QT=ON CUDA_ARCH_BIN=20 CUDA_ARCH_PTX=30 ..

Then run cmake-gui and edit what you want (usually CUDA arch, because it's ignored).

OpenCV 3.3.1

Run:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_CXX_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_OPENGL=ON -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_TIFF=ON -DWITH_OPENEXR=ON -DWITH_PVAPI=ON -DWITH_UNICAP=OFF -DWITH_EIGEN=ON -DWITH_XINE=OFF -DBUILD_TESTS=ON -DCMAKE_SKIP_RPATH=ON -DWITH_CUDA=ON CPU_BASELINE=SSE3 -DWITH_TBB=ON -DWITH_1394=OFF -DWITH_V4L=ON -DPYTHON_LIBRARIES=ON -DWITH_VTK=ON -DWITH_QT=ON -DCUDA_GENERATION=Auto ..

Then run cmake-gui and edit what you want.

OpenCV 3.4

OpenCV 3.4 with CUDA 9.2 (finally works on Debian 9)

Run (in Python's virtual env if you want python support):

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_CXX_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_OPENGL=ON -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_TIFF=ON -DWITH_OPENEXR=ON -DWITH_PVAPI=ON -DWITH_UNICAP=OFF -DWITH_EIGEN=ON -DWITH_XINE=OFF -DBUILD_TESTS=ON -DCMAKE_SKIP_RPATH=ON -DWITH_CUDA=ON CPU_BASELINE=SSE3 -DWITH_TBB=ON -DWITH_1394=OFF -DWITH_V4L=ON -DPYTHON_LIBRARIES=ON -DWITH_VTK=ON -DWITH_QT=ON -DCUDA_GENERATION=Auto -DOPENCV_EXTRA_MODULES_PATH=<PATH_TO_CONTRIB>/modules -DCUDA_NVCC_FLAGS="--expt-relaxed-constexpr" -DENABLE_PRECOMPILED_HEADERS=OFF ..

Then run cmake-gui and edit what you want.

OpenCV 4.2

OpenCV 4.2 with CUDA

Run (in Python's virtual env if you want python support):

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_CXX_FLAGS_RELEASE="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-Wl,-z,relro -Wl,-z,now" -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_OPENGL=ON -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_TIFF=ON -DWITH_OPENEXR=ON -DWITH_PVAPI=ON -DWITH_UNICAP=OFF -DWITH_EIGEN=ON -DWITH_XINE=OFF -DBUILD_TESTS=ON -DCMAKE_SKIP_RPATH=ON -DWITH_CUDA=ON CPU_BASELINE=SSE3 -DWITH_TBB=ON -DWITH_1394=OFF -DWITH_V4L=ON -DPYTHON_LIBRARIES=ON -DWITH_VTK=ON -DWITH_QT=ON -DCUDA_GENERATION=Auto -DOPENCV_EXTRA_MODULES_PATH=<PATH_TO_CONTRIB>/modules -DCUDA_NVCC_FLAGS="--expt-relaxed-constexpr" -DENABLE_PRECOMPILED_HEADERS=OFF OPENCV_GENERATE_PKGCONFIG=ON ..

Other Sources

https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/

PyTorch & TorchVision

For both packages:

python setup.py build develop