1.下载 OpenCV-2.3.1a.tar.bz2

http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/

 

2. 解压

tar -jxvf OpenCV-2.3.1a.tar.bz2 -C extract path

3 编译 安装

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local sourcecode/path

得到 makefile

sudo make install

等待。。。。。。

[  0%] Generating opencv_imgproc_pch_dephelp.cxx
[  1%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.o
Linking CXX static library ../../lib/libopencv_imgproc_pch_dephelp.a
[  1%] Built target opencv_imgproc_pch_dephelp
[  1%] Generating precomp.hpp
[  1%] Generating precomp.hpp.gch/opencv_imgproc_RELEASE.gch
[  2%] Built target pch_Generate_opencv_imgproc
.

.

.

 

 

4. 编译例子

//image_name.c

#include "cv.h"
#include "highgui.h"

int main( int argc, char** argv )
{
   

        IplImage* img;
        if( argc == 2 && (img = cvLoadImage( argv[1], 1)) != 0 )
        {
           

                cvNamedWindow( "Image view", 1 );
                cvShowImage( "Image view", img );
                cvWaitKey(0); // 非常重要,内部包含事件处理循环
                cvDestroyWindow( "Image view" );
                cvReleaseImage( &img );
                return 0;
                 

    }
        return -1;
           

}
 

 

 

 M_cflags=`pkg-config --cflags opencv`
 M_lib=`pkg-config --libs  opencv`
 gcc(g++) -g -W  ${M_cflags}  -o run/image_name  image_name.c ${M_lib}

 

 

运行

./run/image_name