OpenCV 原始RGB图像转换为灰度图像

来源:互联网 发布:网络用语ip是什么意思 编辑:程序博客网 时间:2024/05/17 21:42

按照网上的教程,找来源程序,一个一个输入。

源程序:

#include <cv.h>#include <highgui.h>using namespace cv;int main( int argc, char** argv ){ char* imageName = argv[1]; Mat image; image = imread( imageName, 1 ); if( argc != 2 || !image.data ) {   printf( " No image data \n " );   return -1; } Mat gray_image; cvtColor( image, gray_image, CV_RGB2GRAY ); imwrite( "../../images/Gray_Image.jpg", gray_image ); namedWindow( imageName, CV_WINDOW_AUTOSIZE ); namedWindow( "Gray image", CV_WINDOW_AUTOSIZE ); imshow( imageName, image ); imshow( "Gray image", gray_image ); waitKey(0); return 0;}
结果出现如下错误:

1.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cvtColor(class cv::_InputArray const &,class cv::_OutputArray const &,int,int)" (?cvtColor@cv@@YAXABV_InputArray@1@ABV_OutputArray@1@HH@Z) referenced in function _main。

没办法,只能硬着头皮google,最后在知道,原来是没有添加opencv_imgproc243d.lib;  果断property->Linker->Input  Additional Dependencies 添加opencv_imgproc243d.lib

 本以为这下可以运行了,结果还是报错,把

if( argc != 2 || !image.data )

改为 if!image.data ),运行成功!




原创粉丝点击