OpenCV is the most popular and advanced code library for computer Vision related applications today, spanning fro M many very basic tasks (capture and pre-processing of image data) to high-level algorithms (feature extraction, motion TR ACKing, machine learning). It is free software and provides a rich API in C, C + +, Java and Python. Other wrappers is available. The library itself is platform-independent and often used for real-time image processing and computer vision.
1. Uninstall the previously installed ffmpeg and x264
sudo apt-get-qq remove ffmpeg x264 libx264-dev
2. Install dependencies
sudo apt-get -QQInstall LIBOPENCV-devBuild-essentialCheckinstall CMake Pkg-configYasm Libjpeg-devLibpng-devLibtiff-devLibjasper-devLibavcodec-devLibavformat-devLibswscale-devlibdc1394- A-devLibxine-devLibgstreamer0. Ten-devLibgstreamer-plugins-base0. Ten-devlibv4l-devPython-devPython-numpyLibtbb-devLibqt4-devLibgtk2. 0-devLibfaac-devLibmp3lame-devLibopencore-amrnb-devLibopencore-AMRWB-devLibtheora-devLibvorbis-devLibxvidcore-devx264 v4l-utilsFFmpeg CMake Qt5-defaultCheckinstall
3. Download and unzip OpenCV
wget -OOpenCV-${http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/opencv-"${version}"OpenCV-$version.zipcd opencv-$version
4. Compiling OpenCV with CMake
mkdir BUILDCD Buildcmake- DCmake_build_type=RELEASE- DCmake_install_prefix=/usr/Local - DWith_tbb= on - DBuild_new_python_support= on - Dwith_v4l= on - DInstall_c_examples= on - DInstall_python_examples= on - DBuild_examples= on - DWith_qt= on - DWith_opengl= on ..Make-j2sudo make Installsudo sh- C ' echo '/usr/local/lib ' >/etc/ld.so.conf.d/opencv.conf 'sudo ldconfig
5. Test whether the OPENCV is installed successfully
Enter the sample code directory sample/c, and then
sudo chmod +x build_all.shsudo ./build_all.sh"/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" lena.jpg
Using shell scripts to compile OPENCV programs
#!/bin/bashEcho "Compiling $"if[[ $= = *.c]] ThenGcc-ggdb ' pkg-config--cflags opencv '-O ' basename $. C ' $' Pkg-config--libs OpenCV ';elif[[ $= = *.cpp]] Theng++-ggdb ' pkg-config--cflags opencv '-O ' basename $. cpp ' $' Pkg-config--libs OpenCV ';Else Echo "compile only. C or. cpp Files"fiEcho "Output File = = ${1%.*}"
Name it compile_opencv.sh and place it in the same directory as the source program.
If the following error occurs:
[ -%]Building CXX Object modules/core/cmakefiles/opencv_core.dir/src/system. cpp.o/home/test/autobuild/instance-0/output/build/opencv-2.4. Ten/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) ':/home/test/autobuild/instance-0/output/build/opencv-2.4. Ten/modules/core/src/system. CPP:280:Ten:Error: Inconsistent operand constraintsinchAn' ASM 'make[3]:*** [modules/core/cmakefiles/opencv_core.dir/src/system. CPP.O] Error1
Refer to Core:fix x86 PIC code compilation
Reference: Https://help.ubuntu.com/community/OpenCV
Installing OPENCV in a Linux environment