当argv[1]被重新赋值后,如果数组越界,会把argv[2]中的内容挤掉,argv[2]中存储的是argv[1]中越界的部分
#include <opencv2/opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2/core/core.hpp>
#include <fstream>
#include <iostream>
#include "darknet.h"
#include "time.h"
#include <direct.h>
#include <string.h>
#define MAX_PATH 260
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
int detec_box_num = 0;
try
{
string argv2_backup = argv[2];
cv::Mat frame;
char buffer[MAX_PATH];
std::string exe_abs_path;
_getcwd(buffer, MAX_PATH);
exe_abs_path = buffer;
string na = "//obj.names";
string cf = "//yolo-obj.cfg";
string we = "//yolo-obj_final.weights";
na = exe_abs_path + na;
cf = exe_abs_path + cf;
we = exe_abs_path + we;
darknet detector(na,cf,we);
string img_name = argv[1];
string abs_img_path = exe_abs_path +"//"+ img_name;
strcpy( argv[1],abs_img_path.c_str());
printf("输入图像地址%s", argv[1]);
frame = cv::imread(argv[1]);
clock_t start, finish;
start = clock();
std::vector<bbox_t> result_vec = detector.detect(frame);
detec_box_num = result_vec.size();
finish = clock();
printf(" Predicted in %lf seconds.\n", (double)(finish - start) / CLOCKS_PER_SEC);
detector.draw_boxes(frame, result_vec, detector.obj_names);
printf("原始argv[2]%s\n", argv[2]);
string write_img_name = argv2_backup;
printf("赋值后的argv[2]%s\n", argv[2]);
string abs_img_write_path = exe_abs_path + "//" + write_img_name;
strcpy(argv[2], abs_img_write_path.c_str());
printf("最终的argv[2]%s\n", argv[2]);
cv::imwrite(argv[2], frame);
}
catch (...)
{
return -1;
}
return detec_box_num;
}