如何在python中使用cv2从文件夹导入和显示图像

kzmpq1sx  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(260)

我试图实现这段代码

import glob
import cv2

images = [cv2.imread(file) for file in glob.glob("C:\\Users\\DELL\\OneDrive\\Desktop\\New folder\\*.jpg")]
cv2.imshow(images,mat=0)

但它显示了这个错误:

Traceback (most recent call last):
  File "C:\Users\DELL\PycharmProjects\pythonProject\learn\project3.py", line 5, in <module>
    cv2.imshow(images,mat=0)
TypeError: Can't convert object of type 'list' to 'str' for 'winname'

有人能帮我解决这个问题吗。

polkgigr

polkgigr1#

import glob
import cv2

images = [cv2.imread(file) for file in glob.glob("C:\Users\DELL\OneDrive\Desktop\New folder\*.jpg")] 

for i in range(len(images)):
    cv2.imshow("IMG"+str(i), images[i])    # the arguments of imshow are (name of image, image object)

希望这能奏效!

相关问题