目的
在ubuntu12.04 amd64上配置opencv2.4.8+ffmpeg环境。
实施步骤
1,安装编译工具包
$ sudo apt-get install build-essential cmake
2,配置ffmpeg库
参考内容:http://trac.ffmpeg.org/wiki
2.1 安装依赖
/* $ sudo apt-get install make automake g++ bzip2 python unzip patch subversion ruby build-essential git-core checkinstall yasm texi2html libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvdpau-dev libvorbis-dev libvpx-dev
*/
2.1,安装yasm
可以选择下载yasm-1.2.0.tar.gz或者用git下载
# git clone git://github.com/yasm/yasm.git # cd yasm # ./autogen.sh # ./configure # make # make install
2.2,安装x264编码库
# cd /my/path/where/i/keep/compiled/stuff # git clone git://git.videolan.org/x264.git # cd x264 # ./configure --enable-static --enable-shared # make # make install # ldconfig
引用:http://trac.ffmpeg.org/wiki/How%20to%20quickly%20compile%20libx264、
2.3,配置ffmpeg库
下载了ffmpeg-2.1.5.tar.bz2或者用git下载
# cd /my/path/where/i/keep/compiled/stuff # git clone git://source.ffmpeg.org/ffmpeg.git # cd ffmpeg # ./configure --enable-static --enable-shared --enable-gpl --enable-libx264 # make # make install # ldconfig
]引用:http://trac.ffmpeg.org/wiki/How%20to%20quickly%20compile%20FFmpeg%20with%20libx264%20%28x264%2C%20H.264%29
3,安装opencv2.4.8
官网下载open2.4.8
$ unzip open-2.4.8.zip
$ cd open-2.4.8
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
编译后的配置选项如下,可以看到支持ffmpeg
Linker flags (Release): -- Linker flags (Debug): -- Precompiled headers: YES -- -- OpenCV modules: -- To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab -- Disabled: world -- Disabled by dependency: - -- Unavailable: androidcamera dynamicuda java python -- -- GUI: -- QT: NO -- GTK+ 2.x: NO -- GThread : YES (ver 2.32.4) -- GtkGlExt: NO -- OpenGL support: NO -- -- Media I/O: -- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.3.4) -- JPEG: libjpeg (ver 62) -- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.46) -- TIFF: build (ver 42 - 4.0.2) -- JPEG 2000: build (ver 1.900.1) -- OpenEXR: build (ver 1.7.1) -- -- Video I/O: -- DC1394 1.x: NO -- DC1394 2.x: NO -- FFMPEG: YES -- codec: YES (ver 55.39.101) -- format: YES (ver 55.19.104) -- util: YES (ver 52.48.101) -- swscale: YES (ver 2.5.101) -- gentoo-style: YES -- GStreamer: NO -- OpenNI: NO -- OpenNI PrimeSensor Modules: NO -- PvAPI: NO -- GigEVisionSDK: NO -- UniCap: NO -- UniCap ucil: NO -- V4L/V4L2: NO/YES -- XIMEA: NO -- Xine: NO -- -- Other third-party libraries: -- Use IPP: NO -- Use Eigen: NO -- Use TBB: NO -- Use OpenMP: NO -- Use GCD NO -- Use Concurrency NO -- Use C=: NO -- Use Cuda: NO -- Use OpenCL: YES -- -- OpenCL: -- Version: dynamic -- Include path: /home/havstack/tools/opencv-2.4.8/3rdparty/include/opencl/1.2 -- Use AMD FFT: NO -- Use AMD BLAS: NO -- -- Python: -- Interpreter: /usr/bin/python (ver 2.7.3) -- -- Java: -- ant: NO -- JNI: /usr/lib/jvm/jdk1.7.0_60/include /usr/lib/jvm/jdk1.7.0_60/include/linux /usr/lib/jvm/jdk1.7.0_60/include -- Java tests: NO -- -- Documentation: -- Build Documentation: NO -- Sphinx: NO -- PdfLaTeX compiler: NO -- -- Tests and samples: -- Tests: YES -- Performance tests: YES -- C/C++ Examples: NO -- -- Install path: /usr/local -- -- cvconfig.h is in: /home/havstack/tools/opencv-2.4.8/build -- ----------------------------------------------------------------- -- -- Configuring done -- Generating done -- Build files have been written to: /home/havstack/tools/opencv-2.4.8/build |
$ make -j8
$ sudo make install
# sudo gedit /etc/ld.so.conf.d/opencv.conf # 添加下面这句命令到文件中,文件是空的,不影响。
/usr/local/lib
# ldconfig
# sudo vim /etc/profile # 添加下面两行到文件的末尾。
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
路径配置完毕进行测试:
# cd opencv-2.4.5/samples/c
# chmod +x build_all.sh
# ./build_all.sh
# ./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
参考
http://neicole.blog.51cto.com/5621716/1369620
http://www.2cto.com/os/201309/245506.html