例2.1
#include"highgui.h"
int main( int argc, char**argv)//不要被命令行参数吓倒
{
IplImage* img =cvLoadImage(argv[1]);
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img );
cvWaitKey (0);
cvReleaseImage(&img );
cvDestroyWindow("Example1");
return 0;
}
在这里argc=2,argv[0]=”ch2_ex2_1.exe”,argv[1]=”img.jpg”
程序运行过程:
(1)win+R,输入cmd,确定
(2)切换路径CD C:UserDQADesktopDebug
(3)输入ch2_ex2_1.exe img.jpg
代码改进:
#include"iostream"
#include"highgui.h"
using namespacestd;
int main( int argc, char**argv)
{
IplImage* img =cvLoadImage(argv[1]);
cout<<"argc="<<argc<<"n"<<"argv[0]="<<argv[0]<<"n"<<"argv[1]="<<argv[1]<<endl;
cout<<"img->height="<<img->height<<"n"<<"img->width="<<img->width<<"n"
<<"img->widthStep="<<img->widthStep<<"n"<<"img->nChannels="<<img->nChannels<<endl;
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img );
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Example1");
return 0;
}