批量修改文件夹中的图片名(亲测有用)

最近在做神经网络目标检测时遇到处理的原始图片集的名称比较混乱,难以管理,所以需要更改图片集的名称。
参考:

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,记得关注哦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值