配置简介

opencv使用videocapture读取视频流时,需要借助底层的ffmpeg库。如果不能正确编译,会报错,现记录正确编译配置方法。

ffmpeg源码编译方法记录

opencv依赖于ffmpeg,应该先编译ffmpeg。

git clone https://github.com/FFmpeg/FFmpeg.git -b release/4.3
opencv:4.5.1

./configure --enable-shared  --enable-avresample --enable-gpl --enable-libx264 --prefix=/usr/myffmpg/
make -j$(nproc)
sudo make install

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/myffmpg/lib/
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/myffmpg/lib/pkgconfig/
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:/usr/myffmpg/lib/
//让opencv编译时能搜索到ffmpeg
sudo cp /usr/myffmpg/lib/pkgconfig/* /usr/lib/x86_64-linux-gnu/pkgconfig/

gstreamer命令行安装方法

同样需要安装gstreamer

apt-get install software-properties-common
add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
//gstreamer:
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH

opencv的编译项记录

依赖齐全后,按如下选型编译opencv(带opencv_contrib包)

cmake -DCMAKE_BUILD_TYPE=Debug -DOPENCV_EXTRA_MODULES_PATH=/work/opencv_contrib/modules -DWITH_OPENCL=OFF -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_WITH_DEBUG_INFO=OFF -DBUILD_TESTS=OFF -DWITH_1394=OFF -DWITH_CUDA=OFF -DWITH_CUBLAS=OFF -DWITH_CUFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_OPENCLAMDFFT=OFF -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DINSTALL_TO_MANGLED_PATHS=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_python_bindings_generator=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_calib3d=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_flann=ON -DBUILD_opencv_java_bindings_generator=OFF -DBUILD_opencv_js=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_python3=OFF -DBUILD_opencv_python_tests=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_world=ON -DBUILD_opencv_dnn=ON -D WITH_FFMPEG=ON -D WITH_TIFF=OFF -D BUILD_TIFF=OFF -DWITH_FFMPEG=ON  --DWITH_GSTREAMER=ON  ..

opencv的完整编译安装方法链接

08-23 12:32