对于具有数字规律命名的图像,可以按照下述的代码进行统一缩放
# coding: utf-8
import cv2
import numpy as np
for i in range(1, 10):
# 读取图像
filePath = 'E:/' + str(i) + '.jpg'
img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
# img = cv2.imread(filePath) # 如果用这个,则路径不能有中文
print(np.shape(img))
img2 = cv2.resize(img, (0,0), fx=0.5, fy=0.5) # 按比例缩放
# img2 = cv2.resize(img, (1512,2016)) # 按指定像素大小缩放
# print(np.shape(img2))
cv2.imshow('2', img2) # 显示图像
# 保存图像
cv2.imencode('.jpg', img2)[1].tofile('E:/' + str(i) + '_pressed.jpg')
cv2.waitKey(0) # 保证imshow有效