int main(int argc, char** argv)
1、 argc与argv的默认值(argv相当于数组,尺寸由argc控制)
argc默认为1,因此argv的默认是argv[0]—指向程序运行时的全路径名
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
cout << "argv[0]=" << argv[0] << endl;
cout << "argc=" << argc << endl;
return 0;
}
2、让argv/argv的值指向特定路径
右击项目—>属性—>配置属性—>调试—>命令参数,在命令参数中输入,每个参数之间用空格隔开。
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
for (int i = 0; i < argc; i++)
{
cout << "argv[" << i << "] = " << argv[i] << endl;
}
cout << "argc=" << argc << endl;
Mat img1 = imread(argv[1], 1);
imshow("argv[1]", img1);
Mat img2 = imread(argv[2], 1);
imshow("argv[2]", img2);
waitKey(0);
return 0;
}
?
?
|