一: 预先配置
为使OpenCV的安装在编译时更完备,预先安装好所有的开发平台;
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
二:下载编译opencv
在OpenCV官网下载UNIX的源码包;
Opencv发布版本:http://opencv.org/releases.html
Github:https://github.com/opencv/opencv/releases/tag/2.4.13.2
编译源码:转移到源码文件夹
mkdir opencv
cd opencv
mkdir build
cd build
放置下载的源码文件夹到此目录,例如opencv2.4
cmake -D CMAKE_BUILD_TYPE=Release opencv2.4/
配置完成后,在opencv的配置文件添加路径代码:
sudo
gedit /etc/ld.so.conf.d/opencv.conf
添加代码:
/usr/
local
/lib
Run the following code to configure the library:
sudo
ldconfig
Now you have to open another file:
sudo
gedit /etc/
bash
.bashrc
Add these two lines at the end of the file and save it:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/
local
/lib/pkgconfig
export
PKG_CONFIG_PATH
四:测试安装
打开Python,输入:
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
五:官方的OpenCV编译安装指南
http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/
http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html#gsc.tab=0