ubuntu12.04安装OpenCV2.4。
1分类:opencv2012-06-26 14:411230人阅读评论(0)收藏举报目录(?)[+] The Installation ProcedureTo install and configure OpenCV 2.4.1, complete the following steps. The commands shown in each step can be copy and pasted directly into a Linux command line.1. R emove any installed versions of ffmpeg and x264.sudo apt-get remove ffmpeg x264 libx264-dev2. G et all the dependencies for x264 and ffmpeg.sudo apt-get updatesudo apt-get install build-essential checkinstall git cmakelibfaac-dev libjack-jackd2-dev libmp3lame-devlibopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-devlibtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-devlibxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev3. D ownload and install gstreamer.sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-devgstreamer0.10-tools gstreamer0.10-plugins-baselibgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-goodgstreamer0.10-plugins-ugly gstreamer0.10-plugins-badgstreamer0.10-ffmpeg4. D ownload and install gtk.sudo apt-get install libgtk2.0-0 libgtk2.0-dev5. D ownload and install libjpeg.sudo apt-get install libjpeg8 libjpeg8-dev6. C reate a directory to hold source code.cd ~mkdir src7. D ownload and install install x264.a. Download a recent stable snapshot of x264 fromftp:///pub/videolan/x264/snapshots/. The exact versiondoes not seem to matter. To write this guide, I used versionx264-snapshot-20120528-2245-stable.tar.bz2, but I have usedprevious versions too.cd ~/srcwgetftp:///pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2tar xvf x264-snapshot-20120528-2245-stable.tar.bz2cd x264-snapshot-20120528-2245-stableb. Configure and build the x264 libraries../configure --enable-staticmakesudo make installIMPORTANT: If you are running a 64-bit version of Ubuntu, you mustconfigure x264 as shown in the following command:./configure --enable-shared --enable-picThe -shared and -pic options might also be required when you compilefor some other architectures, such as ARM. You know you need theseoptions if you get the following error when compiling OpenCV:[ 25%] Building CXX objectmodules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.oLinking CXX sharedlibrary ../../lib/libopencv_highgui.so/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o):relocation R_X86_64_32S against `av_destruct_packet' cannot be used when making a shared object; recompile with-fPIC/usr/local/lib/libavcodec.a: could not read symbols: Badvalue8. D ownload and install install ffmpeg.a. Download ffmpeg version 0.11.x from /download.html.cd ~/srcwget /releases/ffmpeg-0.11.tar.bz2tar xvf ffmpeg-0.11.tar.bz2cd ffmpeg-0.11b. Configure and build ffmpeg. //如果是ubuntu是安装在虚拟机上,需要加上--enable-shared./configure --enable-gpl --enable-libfaac--enable-libmp3lame --enable-libopencore-amrnb--enable-libopencore-amrwb --enable-libtheora--enable-libvorbis --enable-libx264 --enable-libxvid--enable-nonfree --enable-postproc --enable-version3--enable-x11grabmakesudo make installIMPORTANT: Just like with x264 in the previous step, you mustconfigure ffmpeg with the -shared option if you are running a 64-bitversion of Ubuntu or some other architectures, such as ARM. The -picoption is not necessary for ffmpeg../configure --enable-gpl --enable-libfaac--enable-libmp3lame --enable-libopencore-amrnb--enable-libopencore-amrwb --enable-libtheora--enable-libvorbis --enable-libx264 --enable-libxvid--enable-nonfree --enable-postproc --enable-version3--enable-x11grab --enable-shared9. D ownload and install install a recent version of v4l (video for linux) from/downloads/v4l-utils/. For this guide I used version 0.8.8.cd ~/srcwget /downloads/v4l-utils/v4l-utils-0.8.8.tar.bz2tar xvf v4l-utils-0.8.8.tar.bz2cd v4l-utils-0.8.8makesudo make install10. Download and install install OpenCV 2.4.1.a. Download OpenCV version 2.4.1 from/projects/opencvlibrary/files/cd ~/srcwget/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.tar.bz2tar xvf OpenCV-2.4.1.tar.bz2b. Create a new build directory and run cmake:cd OpenCV-2.4.1/mkdir buildcd buildcmake -D CMAKE_BUILD_TYPE=RELEASE ..c. Verify that the output of cmake includes the following text:found gstreamer-base-0.10▪GTK+ 2.x: YES▪FFMPEG: YES▪GStreamer: YES▪V4L/V4L2: Using libv4ld. Build and install OpenCV.makesudo make install11. Configure Linux.a. Tell linux where the shared libraries for OpenCV are located by enteringthe following shell command:export LD_LIBRARY_PATH=/usr/local/libAdd the command to your .bashrc f ile so that you don’t have to enterevery time your start a new terminal.Alternatively, you can configure the system wide library search path.Using your favorite editor, add a single line containing thetext/usr/local/lib to the end of a file named/etc/ld.so.conf.d/opencv.conf. In the standard Ubuntu install,the opencv.conf file does not exist; you need to create it. Using vi, forexample, enter the following commands:sudo vi /etc/ld.so.conf.d/opencv.confGo/usr/local/lib< Esc>:wq!After editing the opencv.conf file, enter the following command: sudo ldconfig /etc/ld.so.conf.b. Using your favorite editor, add the following two lines to the end of/etc/bash.bashrc:PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfigexport PKG_CONFIG_PATH8 运行例程测试1 cd ~4 cd openCV_samples/c5 chmod +x build_all.sh6 ./build_all.sh78 ./facedetect--cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"--scale=1.5 lena.jpgMore InformationIf you encounter problems installing OpenCV, see the companion guide, “A Comprehensive OpenCV Installation Troubleshooting Guide.”∙Utkarsh Sinha runs AiShack, a site that has easy-to-understand tutorials using OpenCV to solve real-world problems:http://www.aishack.in/topics/tutorials/∙Sebastian Montabone has several articles on installing OpenCV and image processing. His web site is /∙FakeOutdoorsman’s p osted an excellent dependency install guide, which is located on the Ubuntuforums:/showthread.php?t=786095。