resize_rename.py

import cv2
import os
import shutil

path_A = ‘valA/’
path_B = ‘trainB/’
#path_C = ‘testA/’

out_size = (256,256)
#crop_size = (512,512)
count = 0
for i in os.listdir(path_B):
count += 1
#img_A = cv2.imread(os.path.join(path_A,i))
if not os.path.exists(os.path.join(path_B, i)):
continue
img_B = cv2.imread(os.path.join(path_B,i))
#assert img_A.shape[2] == 3
assert img_B.shape[2] == 3
#img_A_re = cv2.resize(img_A, out_size)
img_B_re = cv2.resize(img_B, out_size)
#cv2.imwrite(os.path.join(path_A, str(count)+’_A.jpg’), img_A_re)
cv2.imwrite(os.path.join(path_B, str(count)+’_B.jpg’), img_B_re)
print count

你可能感兴趣的:(python脚本)