最近在做神经网络目标检测时遇到处理的原始图片集的名称比较混乱,难以管理,所以需要更改图片集的名称。
参考:
https://blog.youkuaiyun.com/hy13684802853/article/details/86677633
具体代码如下:
#include<opencv2\opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
vector<Mat> RenamePic(cv::String Path);
int main()
{
cv::String Path = "F://数据集//目标检测数据集//人//*.jpg";
vector<Mat> images = RenamePic(Path);
return 0;
}
vector<Mat> RenamePic(cv::String Path)
{
vector<cv::String> filenames;
glob(Path, filenames, false);
vector<Mat> images;
size_t count = filenames.size();
for (size_t i = 0; i < count; i++)
{
stringstream str;
int y = i / 10;
str << i << ".jpg";
string img_path = "F://数据集//目标检测数据集//person//";
//命名改为0001-1000格式
string yy;
if (y == 0)
imwrite(img_path + "000"+str.str(), imread(filenames[i]));
else if (y < 10)
imwrite(img_path + "00" + str.str(), imread(filenames[i]));
else if (y < 100)
imwrite(img_path + "0" + str.str(), imread(filenames[i]));
else
imwrite(img_path + str.str(), imread(filenames[i]));
}
return images;
}
运行结果如下:
后续会继续更新基于yolo的行人检测,运行环境Linux+tensorflow,记得关注哦!