OpenCV 4.4 with ffmpeg

jinhasong·2020년 12월 20일
0

opencv

목록 보기
1/1
  • 본 문서는 Ubuntu 환경에서 OpenCV 4.4를 빌드하는 방법에 대하여 설명하는 문서이다.

Environments

  • Ubuntu 18.04
  • CUDA 11.1
  • cuDNN 8.0.4
  • python 3.6

Export workspace path

export WORKSPACE=/path/of/workspace # Example: export WORKSPACE=/workspace
ls ${WOKSPACE}

Remove installed OpenCV

Check version of installed OpneCV

pkg-config --modversion opencv

Remove OpenCV and python-opencv

apt purge libopencv* python-opencv
apt autoremove

Requirements

Install via apt

# Update ubuntu package list and upgrade packages
apt update && apt -y upgrade

# Install packages to compile OpenCV 4.4
apt install -y build-essential cmake pkg-config \
	libjpeg-dev libtiff5-dev libpng-dev \
    	ffmpeg libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev \
    	libv4l-dev v4l-utils \
    	libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
    	libgtk-3-dev \
    	mesa-utils libgl1-mesa-dri libgtkgl2.0-dev libgtkglext1-dev \
    	libatlas-base-dev gfortran libeigen3-dev \
    	python3 python3-dev python3-numpy

Compile and install OpenCV

Download

mkdir ${WORKSPACE}/opencv
cd ${WORKSPACE}/opencv
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.4.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.4.0.zip
unzip opencv.zip
unzip opencv_contrib.zip

Configure

# Create a directory to build
cd ${WORKSPACE}/opencv/opencv-4.4.0
mkdir build
cd build

# Configure using cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=ON \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PACKAGE=OFF \
-D BUILD_EXAMPLES=OFF \
-D WITH_TBB=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-D WITH_CUDA=ON \
-D WITH_CUBLAS=ON \
-D WITH_CUFFT=ON \
-D WITH_NVCUVID=ON \
-D WITH_IPP=OFF \
-D WITH_V4L=ON \
-D WITH_1394=OFF \
-D WITH_GTK=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D WITH_EIGEN=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D BUILD_JAVA=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D OPENCV_SKIP_PYTHON_LOADER=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=${WORKSPACE}/opencv/opencv_contrib-4.4.0/modules \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D CUDA_ARCH_BIN=7.5 \
-D CUDA_ARCH_PTX=7.5 \
-D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.8.0.4 \
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.6m \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include/ \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
-D PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 \
-D PYTHON3_EXECUTABLE=/usr/bin/python3 \
-D CUDNN_INCLUDE_DIR=/usr/local/cuda/include ..

Compile and install

make -${PROC}
make -${PROC} install
ldconfig
profile
Jinha Song

0개의 댓글