import os
import cv2 as cv
path = './LowRes' #文件夹目录
savepath = "./NewLowRes" # 保存文件夹
files= os.listdir(path) #得到文件夹下的所有文件名称
total_num = len(files) #得到文件夹中图像的个数
for i in range(total_num):
filename = path + '/' + files[i]
img = cv.imread(filename)
top_size, bottom_size, left_size, right_size = (0, 0, 18, 18)
constant = cv.copyMakeBorder(img, top_size, bottom_size, left_size, right_size, cv.BORDER_CONSTANT,
value=(0, 0, 0))
#保存图像
savejpg_name = savepath + '/LowRes' + str(i + 1) + '.jpg' #拼接保存图像的地址
cv.imwrite(savejpg_name, constant)
``
|