import re
import cv2 as cv
import numpy as np
import os
#读取所有图像 ,重命名为VOC格式,选取部分图像进行平移变换
import os.path
import glob
SourceImgPath = "C:\\RenameImgToVoc\\output"+'\\'
SacePath = "C:\\RenameImgToVoc\\input"+'\\' #双斜杠表示单斜杠 在windows中
total_sou = os.listdir(SourceImgPath)
img_start = 86
ImageNameFormat = '.jpg'
for img_source in total_sou:
#获得文件夹下所有文件的路径
ImgPath = os.path.join('%s%s' % (SourceImgPath, img_source))
print("ImgPath"+ImgPath)
#构造新名字
ImageNameNumStart = str(img_start ).zfill(6)
ImageName = ImageNameNumStart + ImageNameFormat
#读取图像
#有问题
img = cv.imread(ImgPath, 1)
#保存图像
print(SacePath + ImageName)
cv.imwrite(os.path.join('%s%s' % (SacePath, ImageName)), img)
img_start = img_start + 1
'''
去掉字符串中的括号
s= '(001).jpg'
re.sub('[\(\)]','',s)
数字字符串获取固定长度的数值,不够的左边补0
stk_code = 1
stk_code = str(stk_code).zfill(6)
print(stk_code )
输出结果:000001
'''
python pycharm读取文件夹下所有图像文件,改变名称后存放到另一文件夹下
最新推荐文章于 2022-05-15 00:35:53 发布