繁体   English   中英

在python中使用openCV调整图像大小

[英]Resize images using openCV in python

我有以下方法从目录中获取所有图像:

def ReadImages(Path):
    LabelList = list()
    ImageCV = list()
    classes = ["nonPdr", "pdr"]
    width = 605
    height = 700
    dim = (width, height)


    # Get all subdirectories
    FolderList = os.listdir(Path)

    # Loop over each directory
    for File in FolderList:
        if(os.path.isdir(os.path.join(Path, File))):
            for Image in os.listdir(os.path.join(Path, File)):
                # Convert the path into a file
                ImageCV.append(cv2.imread(os.path.join(Path, File) + os.path.sep + Image))
                # Add a label for each image and remove the file extension
                LabelList.append(classes.index(os.path.splitext(File)[0]))
        else:
            ImageCV.append(cv2.imread(os.path.join(Path, File) + os.path.sep + Image))    
            # Add a label for each image and remove the file extension
            LabelList.append(classes.index(os.path.splitext(File)[0]))
    return ImageCV, LabelList

但是我的图像更大,并且想将其 wxh 减小到 605x700,然后我尝试执行以下操作:

imgR = cv2.resize(ImageCV[Image])

它不起作用.. 我能做些什么来调整所有这些图像的大小? 我很感激任何帮助。

您可能必须将形状传递给cv2 resize()函数。

这将调整图像大小以具有 605 列(宽度)和 700 行(高度):

imgR = cv2.resize(ImageCV[Image], (605, 700)) 

有关更多选项,您可以阅读cv2.resize的文档。

另外,我建议使用 python 编码约定,如imgR -> img_rImage -> imageImageCV -> image_cv等。希望这会ImageCV -> image_cv帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM