You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
937 B

import os
import cv2 as cv
if __name__ == '__main__':
#创建文件夹
path='./'
new_path='./dist/'
if not os.path.exists(new_path):
os.mkdir(new_path)
# 输入起始数字大小
start=input("请输入起始编号:\n")
start=int(start)
for filename in os.listdir(path):
if filename.endswith('.jpg'):
img = cv.imread(path+filename)
#根据不同的长宽比来确定输出文件尺寸
if img.shape[0]>img.shape[1]:
new_img=cv.resize(img,(600,800),cv.INTER_LINEAR)
else:
new_img = cv.resize(img, (800, 600), cv.INTER_LINEAR)
output_name=str(start).zfill(6)+'.jpg'
print("正在导出图片{}\n".format(output_name))
cv.imwrite(new_path+output_name,new_img)
start=start+1
print("================================\n")
print("图片全部处理完成!\n")