Ubuntu下安装opencv

系统: Ubuntu 10.04

(1) 安装依赖包

 

$ sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

 

(2) 下载OpenCV-2.0.0

 

$ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.0/OpenCV-2.0.0.tar.bz2/download

$ tar -xvf OpenCV-2.0.0.tar.bz2

$ cd OpenCV-2.0.0

 

 

(3) 配置编译环境

 

$ ./configure --prefix=/usr/local --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing

 

(4) 编译、安装

$ make

$ make install

 

(5) 配置库路径,加入环境变量

$ sudo gedit /etc/ld.so.conf.d/opencv.conf

添加opencv库的安装路径:

/usr/local/lib

$ sudo ldconfig

 

$ sudo gedit /etc/bash.bashrc

添加PKG_CONFIG_PATH变量:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

 

(6) 测试

$ cd ~

$ mkdir openCV_samples

$ cp /usr/local/share/opencv/samples/c/* openCV_samples

$ cd openCV_samples

$ chmod +x build_all.sh

$ ./build_all.sh

 

$ ./drawing

$ ./bgfg_segm tree.avi

 

(7) 实例

$ mkdir hello

$ cd hello

$ vim hello.c

#include #include #include int main( int argc, char *argv[] ) { char *filename = "lena.jpg"; IplImage* pImg = cvLoadImage( filename, 1); cvNamedWindow( "lena", CV_WINDOW_AUTOSIZE ); cvShowImage( "lena", pImg ); cvWaitKey( 0 ); cvDestroyWindow( "lena" ); cvReleaseImage( &pImg ); return 0; } 

$ gcc `pkg-config --cflags --libs opencv` hello.c -o hello

$ ./hello

 

 

 

 

你可能感兴趣的:(OpenCV,LINUX)