opencv2.1链接lib文件时需注意区分debug与release

今年4月份opencv就出了2.1版本,一直没怎么用过,今天用了下,发现它越来越向Matlab的image processing toolbox靠近了,比如读入图像可以用imread(),显示图像用imshow().写了个最简单不过的例子,读入图像然后显示出来:

代码
   
     
#include " cv.h " // include standard OpenCV headers, same as before
#include " highgui.h "
#include
< stdio.h >

using namespace cv; // all the new API is put into "cv" namespace. Export its content

int main( int argc, char ** argv )
{
const char * imagename = " lena.jpg " ;

Mat img
= imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function
if (img.empty())
{
fprintf(stderr,
" Can not load image %s\n " , imagename);
return - 1 ;
}

if ( ! img.data ) // check if the image has been loaded properly
return - 1 ;

// this is counterpart for cvNamedWindow
namedWindow( " image " , CV_WINDOW_AUTOSIZE);
imshow(
" image " , img);
waitKey();
return 0 ;
}

 

运行时却总说没有找到图片,可我的图片明明就在当前文件夹下。后来发现是Project property设置的有问题:在工程设置里Project->Property->Linker->Input的Additional Dependencies,我以前习惯于不区分debug和release,全部用release版,这在2.1之前的版本似乎没问题,但在2.1里,debug下就必须用debug版,即使用cv210d.lib cxcore210d.lib highgui210d.lib

大家可以尝试下看有没有我说的问题。

你可能感兴趣的:(opencv)