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
#include
usingnamespacecv;
intmain(intargc,char**argv)
{
if(argc!=2)
{
printf("usage:DisplayImage.out\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:
cmake_minimum_required(VERSION2.8)
project(DisplayImage)
find_package(OpenCVrequired)
add_executable(DisplayImageDisplayImage.cpp)
target_link_libraries(DisplayImage${OpenCV_LIBS})
(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
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!