1. Install OpenCV in Ubuntu:
(1) Update the list of package repositories:
- sudoapt-getupdate
- sudoapt-getupgrade
(2) Remove prevIoUsly installed FFMPEG and x264 libraries:
- sudoapt-getremoveffmpegx264-dev
(3) Install the necessary packages for compiling the OpenCV sources:
- sudoapt-getinstallocl-icd-libopencl1build-essentialcheckinstallcmakepkg-configyasmlibjpeg-devlibjasper-devlibavcodec-devlibavformat-devlibswscale-devlibdc1394-22-devlibxine2-devlibgstreamer0.10-devlibgstreamer-plugins-base0.10-devlibv4l-devpython-devpython-numpylibtbb-devlibqt4-devlibgtk2.0-devlibfaac-devlibmp3lame-devlibopencore-amrnb-devlibopencore-amrwb-devlibtheora-devlibvorbis-devlibxvidcore-devx264v4l-utils
(4) Make a directory to download and build OpenCV:
- mkdiropencv
- cdopencv
(5) Download the OpenCV sources for Linux,then unzip it:
- wget-Oopencv-2.4.10.ziphttp://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
- unzipopencv-2.4.10.zip
- cdopencv-2.4.10
(6) Create a directory to compile the OpenCV sources:
- mkdirbuild
- cdbuild
(7) Building OpenCV sources with CMake and install:
- cmake-DCMAKE_BUILD_TYPE=RELEASE-DCMAKE_INSTALL_PREFIX=/usr/local-DWITH_TBB=ON-DINSTALL_PYTHON_EXAMPLES=ON-DBUILD_EXAMPLES=ON-DWITH_QT=ON-DWITH_OPENGL=ON..
(8) Make and install:
- make
- sudomakeinstall
- sudosh-c'echo"/usr/local/lib">/etc/ld.so.conf.d/opencv.conf'
- sudoldconfig
(9) Restart the system for everything to take effect:
- sudoshutdown-rnow
2. Test OpenCV in Ubuntu:
(1) Create a directory DisplayImage for test project:
- mkdirDisplayImage
- cdDisplayImage
(2) Create DisplayImage.cpp and edit it:
- geditDisplayImage.cpp
Then edit the DisplayImage.cpp:
- #include<stdio.h>
- #include<opencv2/opencv.hpp>
- usingnamespacecv;
- intmain(intargc,char**argv)
- {
- if(argc!=2)
- {
- printf("usage:DisplayImage.out<Image_Path>\n");
- return-1;
- }
- Matimage;
- image=imread(argv[1],1);
- if(!image.data)
- {
- printf("Noimagedata\n");
- return-1;
- }
- namedWindow("DisplayImage",CV_WINDOW_AUTOSIZE);
- imshow("DisplayImage",image);
- waitKey(0);
- return0;
- }
(3) Create a CMake file:
- geditCMakeLists.txt
Then edit the CMakeLists.txt:
(4) Generate the executable file:
- cmake.
- make
(5) Execute it:
- ./DisplayImagelena.jpg
lena.jpg is the test image
ffmpeg error:
cmake ........ -D WITH_FFMPEG=OFF