一、 opencv环境的搭建
1、直接使用源安装
$ apt-cache search opencv
harpia - Image Processing/Computer Vision Automatic Prgm. Tool
libcv-dev - development files for libcv
libcv1 - computer vision library
libcvaux-dev - development files for libcvaux
libcvaux1 - computer vision extension library
libhighgui-dev - development files for libhighgui
libhighgui1 - computer vision GUI library
opencv-doc - OpenCV documentation and examples
python-opencv - Python bindings for the computer vision library
直接执行以下命令即可
$sudo agt-get install harpia
$sudo agt-get install libcv-dev
$sudo agt-get install libcv1
$sudo agt-get install libcvaux-dev
$sudo agt-get install libcvaux1
$sudo agt-get install ibhighgui-dev
$sudo agt-get install libhighgui1
$sudo agt-get install opencv-doc
$sudo agt-get install python-opencv
直接将上述列出的全部安装上,就可以使用OpenCV编写代码。
编译出错的话执行:$cp /usr/local/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig
二、 如何使用opencv
创建test.c,内容如下:
#include <highgui.h>
int main()
{
IplImage* image = cvLoadImage("1.jpg");
if (NULL == image)
exit(1);
cvNamedWindow("Example",CV_WINDOW_AUTOSIZE);
cvShowImage("Example",image);
cvWaitKey(0);
cvReleaseImage(&image);
cvDestroyWindow("Example");
return 0;
}
在test.c相同目录下放入一张1.jpg的图片,执行如下命令编译
$g++ `pkg-config opencv --libs --cflags opencv` test.c -o test
会得到可执行程序test
$./test
就可以看到效果了。
三、 在linux环境下使用qtcteator+opencv编程
用qtcreator建立工程,在.pro里面添加如下内容:
INCLUDEPATH += /usr/include/opencv
LIBS += /usr/lib/libcv.so /usr/lib/libcvaux.so /usr/lib/libcxcore.so /usr/lib/libhighgui.so /usr/lib/libml.so
然后在终端输入命令:$sudo gedit /usr/share/qt4/mkspecs/default/qmake.conf
在qmake.conf里面添加如下内容:
QMAKE_INCDIR = /usr/include/opencv
QMAKE_LIBS = -lcvaux -lcv -lcxcore -lhighgui –lml
那么test.c里面的程序就可以通过qtcreator编译和运行了。
四、 参考资料
1. Learning OpenCV中文版.pdf http://ishare.iask.sina.com.cn/f/21549768.html?from=like
2. Linux环境下的Qt添加OpenCV的配置 http://www.byywee.com/page/M0/S527/527539.html
3. 个人整理的opencv最基本入门资料http://wenku.baidu.com/view/2b6fb9eb856a561252d36f4f.html