(原)ubuntu 下安装opencv
在ubuntu 10.04下安装opencv,步骤如下:
1、找到opencv的依赖包
$ sudo apt-cache search opencv libcv-dev - development files for libcv libcv4 - computer vision library libcvaux-dev - development files for libcvaux libcvaux4 - computer vision extension library libhighgui-dev - development files for libhighgui libhighgui4 - computer vision GUI library opencv-doc - OpenCV documentation and examples python-opencv - Python bindings for the computer vision library harpia - Image Processing/Computer Vision Automatic Prgm. Tool
2、安装opencv
$ sudo apt-get install libcv-dev libcv4 libcvaux-dev libcvaux4 libhighgui-dev libhighgui4 opencv-doc harpia
3、在CodeBlocks中配置opencv
点击Settings ->Compiler and debugger settings,在Linker settings的Other linker options:里添加 -lcv -lcxcore -lhighgui。在Search directories -> Compier 下添加目录 /usr/include/opencv,在右边的Linker标签下添加目录/usr/lib
4、示例代码
/* * 例示1:用于从磁盘加载并在屏幕上显示一幅图像 */ #include <iostream> #include <highgui.h> using namespace std; int main( int argc, char *argv[] ) { if( argc < 2) { cout<< "Usage:" << argv[0] << "<image_name>" << endl; return 1; } IplImage *img = cvLoadImage( argv[1] ); if( !img ) { cout<< argv[1] << "image load error." << endl; return 1; } cvNamedWindow( "Exampe1: LoadImage", CV_WINDOW_AUTOSIZE ); cvShowImage( "Example1", img ); cvWaitKey( 0 ); cvReleaseImage( &img ); cvDestroyWindow( "Example1" ); return 0; }
(要运行此示例,需要设置项目参数,具体如下:Project -> set programs' arguments...,在Program arguments下输入要显示的图片的名字。)