기본 패키지 설치Mac명령어 (only opencv)명령어 v2 (opencv + contrib)명령어 v3 (opencv + contrib + python)명령어 v4 (opencv + contrib + cuda)설치 완료참고예제 코드 실행
기본 패키지 설치
# Install minimal prerequisites (Ubuntu 18.04 as reference) sudo apt update && sudo apt install -y cmake g++ wget unzip sudo apt-get install -y qtbase5-dev qtdeclarative5-dev
Mac
alias nproc="sysctl -n hw.logicalcpu" brew install ninja
git clone https://github.com/opencv/opencv.git mkdir build/ mkdir install/ cd build cmake -DCMAKE_BUILD_TYPE=Release -D BUILD_ZLIB=OFF -DCMAKE_INSTALL_PREFIX=../install -GNinja ../opencv time ninja
명령어 (only opencv)
git clone https://github.com/opencv/opencv.git mkdir build/ mkdir install/ cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../install ../opencv make -j"$(nproc)" sudo make install
명령어 v2 (opencv + contrib)
# Download and unpack sources wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip unzip opencv.zip unzip opencv_contrib.zip # Create build directory and switch into it mkdir -p build && cd build # Configure cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x # Build cmake --build .
명령어 v3 (opencv + contrib + python)
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip unzip opencv.zip unzip opencv_contrib.zip mkdir build/ mkdir install/ cd build cmake -DCMAKE_BUILD_TYPE=Release -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_opencv_python3=ON -D HAVE_opencv_python3=ON -DPYTHON_DEFAULT_EXECUTABLE=$(which python3) -DCMAKE_INSTALL_PREFIX=../install -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x make -j"$(nproc)" sudo make install
명령어 v4 (opencv + contrib + cuda)
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.5.zip wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.5.zip unzip opencv.zip unzip opencv_contrib.zip mkdir build/ mkdir install/ cd build cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=../install -DWITH_CUDA=ON -DENABLE_FAST_MATH=1 -DCUDA_FAST_MATH=1 -DWITH_CUBLAS=1 -DBUILD_opencv_cudacodec=OFF -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=OFF -DWITH_TBB=OFF -DWITH_MKL=ON -DMKL_USE_MULTITHREAD=ON -DMKL_WITH_TBB=ON -DWITH_IPP=ON -DWITH_GDAL=ON -DWITH_XINE=OFF -DBUILD_EXAMPLES=OFF -DCUDA_ARCH_PTX="" -DCUDA_ARCH_BIN="6.2" -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ../opencv make -j"$(nproc)" sudo make install
설치 완료
참고
예제 코드 실행
#include "opencv2/opencv.hpp" #include <iostream> using namespace std; int main() { cout << CV_VERSION << endl; return 0; }