OpenCV is the most popular and advanced code library for Computer Vision related applications today, spanning from many very basic tasks (capture and pre-processing of image data) to high-level algorithms (feature extraction, motion tracking, machine learning). It is free software and provides a rich API in C, C++, Java and Python. Other wrappers are available. The library itself is platform-independent and often used for real-time image processing and computer vision.html
1.移除先前安裝的ffmpeg和x264python
1 sudo apt-get -qq remove ffmpeg x264 libx264-dev
2.安裝依賴項git
1 sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libpng-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg cmake qt5-default checkinstall
有時會提示說,找不到ffmpeg軟件包。github
解決方法:shell
E: 軟件包 gstreamer0.10-ffmpeg 沒有可供安裝的候選者bash
好吧,裝不上來,由於在Ubuntu上gstreamer0.10-ffmpeg屬於額外的版權受限程序,gstreamer0.10-ffmpeg包可經過一些第三方的PPA源,可是
全部您須要作的就是添加PPA到您的系統,更新本地存儲索引和安裝gstreamero.10-ffmpeg包。以下輸入命令:app
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install gstreamer0.10-ffmpeg
---------------------
做者:Jack_Kuo
來源:CSDN
原文:https://blog.csdn.net/weixin_37251044/article/details/78380303
版權聲明:本文爲博主原創文章,轉載請附上博文連接!ide
3.下載並解壓OpenCV測試
1 wget -O OpenCV-$version.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/opencv-"$version".zip/download 2 unzip OpenCV-$version.zip 3 cd opencv-$version
4.編譯源碼,構建OpenCVui
1 mkdir build 2 cd build 3 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. 4 make -j2 5 sudo make install 6 sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' 7 sudo ldconfig
5.測試OpenCV是否安裝成功
轉到opencv的樣例代碼目錄(samples/c)下,
1 chmod +x build_all.sh 2 ./build_all.sh 3 ./facedetect "/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" lena.jpg
運行結果:
編譯OpenCV程序:
1 #!/bin/bash 2 echo "compiling $1" 3 if [[ $1 == *.c ]] 4 then 5 gcc -ggdb `pkg-config --cflags opencv` -o `basename $1 .c` $1 `pkg-config --libs opencv`; 6 elif [[ $1 == *.cpp ]] 7 then 8 g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`; 9 else 10 echo "Please compile only .c or .cpp files" 11 fi 12 echo "Output file => ${1%.*}"
將上面代碼保存成shell腳本,在每次編譯程序時調用便可。
若是在編譯過程當中出現以下錯誤:
1 [ 14%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o 2 /home/test/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp: In function '(static initializers for /home/test/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp)': 3 /home/test/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp:280:10: error: inconsistent operand constraints in an 'asm' 4 make[3]: *** [modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1
可參考:https://github.com/Itseez/opencv/commit/ea50be0529c248961e1b66293f8a9e4b807294a6