首页 > 解决方案 > 无法将调整大小的图像保存在 cv2 的特定文件夹中

问题描述

我正在尝试在 python 中编写代码以从特定文件夹批量调整图像大小并将输出保存到不同的指定文件夹。我无法将图像保存在提到的文件夹名称为“Resized”的 outPath 中。任何人都可以帮我解决这个问题...

import os
import cv2, glob

imgPath = "E:/Data/Ori"
outPath = "E:/Data/Resized"

images = glob.glob(imgPath + "/" + "*.jpg")

for image in images:
    img = cv2.imread(image,1) #1 for color scale
    
    res = cv2.resize(img, (400,300)) #width = 400, height = 300
    
    cv2.imwrite(outPath + '/' + image, res) #Unable to save the images in 'Resized' folder

标签: pythonfilepathglobcv2

解决方案


推荐阅读