[英]How to read in a directory of images with OpenCV
I'm trying to read this directory of jpg
images and add them to a list but the list is empty when I run this code:我正在尝试读取此
jpg
图像目录并将它们添加到列表中,但是当我运行此代码时列表为空:
import glob
import cv2
cv_img = []
for img in glob.glob("E:/project/file/*.jpg"):
n= cv2.imread(img)
cv_img.append(n)
You can use a list comprehension to read each image into a list.您可以使用列表推导将每个图像读入列表。 Also ensure that the relative path you're passing in to glob exists otherwise the list may be empty
还要确保您传递给 glob 的相对路径存在,否则列表可能为空
import cv2
import glob
images = [cv2.imread(image) for image in glob.glob("images/*.jpg")]
for image in images:
cv2.imshow('image', image)
cv2.waitKey(1000)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.