ubuntu16.04下安装opencv

1 依赖包
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
2 下载源码
wget https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip
解压
3 在解压目录下创建子目录release
mkdir release;cd release
4 编译安装
4.1 cmake生成make文件
cmake -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.2 make
4.3 make install


测试
cd ~/OpenCV-2.4.9/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




ffmpeg安装
源码下载 : svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
文件配置 : ./configure --enable-shared --prefix=/usr

安装 : make && make install






三:配置Library

      打开/etc/ld.so.conf.d/opencv.conf,在末尾加入/usr/local/lib ;

      编辑添加目录:    

[python] view plain copy
  1. sudo ldconfig  

      编辑/etc/bash.bashrc,加入

[python] view plain copy
  1. PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
  2. export PKG_CONFIG_PATH  

四:测试安装

       打开Python,输入:

[cpp] view plain copy
  1. import cv2.cv  as cv  

       或者:将opencv源码包下的example/c拷贝出来,执行./build_all.sh
       编译完后试一个人脸检测的程序:

    ./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

Tips:
       1.关于Bash编译方法,参照opencv源码下example/c/build_all.sh
       2.有些路径的OpenCV注意大小写,如example/c下facedetect运行时的路径

  

五:官方的OpenCV编译安装指南

         http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/

你可能感兴趣的:(机器学习)