简体   繁体   English

如何使用 OpenCV 读取图像目录

[英]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.

相关问题 如何使用Python和OpenCV从目录中读取图像? - How to read images from a directory with Python and OpenCV? 如何使用 OpenCV 和 numpy 从 Drive 目录读取和显示图像? - How to read and display images from a Drive directory using OpenCV and numpy? 从特定目录读取多个图像,使用 python 和 opencv 将它们保存在另一个目录中 - Read multiple images from specific directory, prepossessed and save them another directory using python and opencv 如何使用 opencv 读取通过 post 请求上传的图像 - How to read images uploaded via post request using opencv Python - Opencv 读取 qr 图像 - Python - Opencv to read qr images 使用Python和OpenCV处理目录中的图像 - Processing Images from a directory using Python and OpenCV 在opencv中读取、预处理和保存图像到指定位置 - Read, preprocess, and save images to specified location in opencv 无法在python中使用opencv读取图像 - Unable to read images using an opencv in python 如何在不使用 OpenCV 库的情况下在 Python 中读取多通道 16 位每通道图像? - How to read multi-channel 16-bit-per-channel images in Python without using OpenCV library? 如何在 Python 中使用 opencv 从文件夹中读取图像序列(im1、im2、...)? - How can I read a sequence of images (im1, im2, ...) from a folder using opencv in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM