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. Remove the previously installed ffmpeg and x264
1 sudo apt-get-qq remove ffmpeg x264 libx264-dev
2. Install dependencies
1 sudo Install pkg-config yasm libjpeg-dev libpng-dev libtiff5-dev libjasper-dev libavcodec-dev Libavformat-dev Libswscale-dev libdc1394--dev libxine-dev Libgstreamer0. Ten-dev libgstreamer-plugins-base0. Ten-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
3. Download and unzip OpenCV
1 wget -o opencv-$version. zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/opencv-"$ Version ". Zip/download2unzip opencv-$version. Zip 3 CD opencv-$version
4. Compile the source code, build OpenCV
1 mkdirBuild2 CD Build3cmake-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-J25 sudo Make Install6 sudo SH-C'echo "/usr/local/lib" >/etc/ld.so.conf.d/opencv.conf'7 sudoLdconfig
5. Test whether the OPENCV is installed successfully
Go to OpenCV Sample code directory (SAMPLES/C),
1 chmod +x build_all. SH 2 ./build_all. SH 3 " /usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml " lena.jpg
Operation Result:
To compile the OPENCV program:
1#!/bin/Bash2 Echo "Compiling $"3 if[[ $1== *. c]]4 Then5 GCC-ggdb 'Pkg-config--cflags OpenCV '-O 'basename$1. C ' $1`Pkg-config--Libs OpenCV ';6 elif[[ $1== *.CPP ]]7 Then8g++-ggdb 'Pkg-config--cflags OpenCV '-O 'basename$1.CPP` $1`Pkg-config--Libs OpenCV ';9 ElseTen Echo "compile only. C or. cpp files" One fi A Echo "Output File = = ${1%.*}"
Save the above code as a shell script, which is called every time the program is compiled.
If the following error occurred during the compilation process:
1[ -%] Building CXXObjectModules/core/cmakefiles/opencv_core.dir/src/system.CPP. O2/home/test/autobuild/instance-0/output/build/opencv-2.4.Ten/modules/core/src/system.CPP: Infunction '(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.Ten/modules/core/src/system.CPP:280:Ten: error:inconsistent operand constraintsinchAn'ASM'4 Make[3]: * * * [Modules/core/cmakefiles/opencv_core.dir/src/system.CPP. O] Error1
Refer to: HTTPS://GITHUB.COM/ITSEEZ/OPENCV/COMMIT/EA50BE0529C248961E1B66293F8A9E4B807294A6
Environment construction of OPENCV under Linux