c++ opencv 遍历文件夹中的图像&&以时间命名图像

遍历文件夹中的图像

cv::String folder = "C:\\Users\\ASUS\\c++Project\\pictures";
std::vector<cv::String> imagePathList;
cv::glob(folder, imagePathList);
for (int i = 0; i < imagePathList.size(); i++)
{
	std::cout << imagePathList[i] << "\n";
	cv::Mat img = cv::imread(imagePathList[i]);
	vector<YOLOV5::CheckAIData>res;
	yolo_dll->CheckAI(_sampleName, img, res);
	cout << "检测的个数为: " << res.size() << endl;
}

用时间命名图像

#include "ctime"
#include "time.h"
FILE *fp = NULL;
time_t timep;
struct tm *p;
char name[256] = { 0 };
time(&timep);//获取从1970至今过了多少秒,存入time_t类型的timep
p = localtime(&timep);//用localtime将秒数转化为struct tm结构体
sprintf(name, "%s%d%d%d%d%02d%02d.bmp", 
"C:\\Users\\ASUS\\c++Project\\Chip_Detection_YOLO\\detection_yolo\\detection_yolo\\test\\", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min,p->tm_sec);//把格式化的时间写入字符数组中
printf("创建文件名称为:%s\n", name);
cv::imwrite(name, img);

你可能感兴趣的:(c++opencv,opencv,c++,人工智能)