在Ubuntu下安装OpenCV

Ubuntu系统版本:Ubuntu Kylin 14.04
OpenCV软件版本:opencv-2.4.10
Opencv官网:opencv.org

在download中下载opencv-2.4.10中OpenCV for Linux/Mac
按照THE INSTALLATION的步骤安装,网址:
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation

提前需要的依赖包:
GCC 4.4.x or later. This can be installed with:
CMake 2.6 or higher;
Git;
GTK+2.x or higher, including headers (libgtk2.0-dev);
pkg-config;
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy);
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev;
[optional] libdc1394 2.x;
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev.

输入命令:
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev libdc1394 2.x libjpeg-dev libpng-dev libtiff-dev libjasper-dev

sudo apt-get update
sudo apt-get upgrade

将opencv-2.4.10解压缩到当前目录:
unzip opencv-2.4.10.zip
或者将其解压缩到指定目录:
unzip opencv-2.4.10 -d

用CMake创建OpenCV
基本格式是:
cmake []

cd ~/opencv-2.4.10
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ~//opencv-2.4.10

在CMake成功后
make
sudo make install

在make过程中如果出现类似以下问题:
[ 14%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o  /home/test/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp: In function '(static initializers for /home/test/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp)':  /home/test/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp:280:10: error: inconsistent operand constraints in an 'asm'  make[3]: *** [modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1
可以参照网址中的办法,在system.cpp中进行删改:
https://github.com/Itseez/opencv/commit/ea50be0529c248961e1b66293f8a9e4b807294a6

配置openCV参数设置
在/etc/ld.so.conf.d/opencv.conf文件中加入一行:/usr/local/lib ,
可能会没有opencv.conf这个文件,那我们就自己创建一个:
sudo gedit/etc/ld.so.conf.d/opencv.conf
使用下面这条命令:
sudo ldconfig
在 /etc/ bash.bashrc(sudo gedit/etc /bash.bashrc以root进入才能修改)中加入:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

至此,OpenCV安装配置完毕

测试:
将opencv源码包下的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

结果如下:

你可能感兴趣的:(图像处理,Linux)