【发布时间】:2020-05-19 20:18:22
【问题描述】:
我尝试读取一堆图像(超过 180k)并将它们调整为新的高度和新的宽度。我使用下面的代码,它适用于少量图像,但对于大量图像,内核会死掉......那么,有没有更有效的方法来调整图像大小?也许没有阅读其中的图像?
folders = glob.glob(r'path\to\images\*')
imagenames_list = []
for folder in folders:
for f in glob.glob(folder+'/*.png'):
imagenames_list.append(f)
read_images = []
for image in imagenames_list:
read_images.append(cv2.imread(image))
def resize_images(img, new_width, new_height):
size = (new_width, new_height)
resized_img = cv2.resize(img, size)
return resized_img
resized_img = [resize_images(img, new_width=128, new_height=32) for img in read_images]
【问题讨论】:
-
您可以使用 imagemagick 的转换实用程序将它们保存在磁盘上您需要的大小,然后仅在需要时加载调整大小的图像
-
在这种情况下,使用@shortcipher3 建议的命令行工具进行预处理是可行的方法。
标签: python image opencv image-resizing