python - 有没有一种方法可以将多个图像保存到python中的数组中供以后使用?

标签 python python-3.x opencv computer-vision opencv-python

我正在使用opencv python。我有一个嵌套的for循环,每次循环都会生成一个图像。有没有一种方法可以将这些图像保存到数组中以供以后查看,或者有一种方法可以在每次迭代中分别保存每个图像?

最佳答案

是的,有可能。您可以简单地使用append()函数将每个图像添加到数组中。

假设您在文件中有 * .jpg 格式的图像。在循环中,您可以读取每个图像并将它们附加到数组中。循环完成后,您可以从数组中调用所需的图像,并使用imshow()显示它们

这是示例代码:

import cv2
import glob
import numpy as np


image_array = [] // array which ll hold the images
files = glob.glob ("*.jpg")
for myFile in files:
    image = cv2.imread (myFile)
    image_array.append (image) // append each image to array
// this will print the channel number, size, and number of images in the file
print('image_array shape:', np.array(image_array).shape) 

cv2.imshow('frame', image_array[0])

cv2.waitKey(0) 

关于python - 有没有一种方法可以将多个图像保存到python中的数组中供以后使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62272774/

相关文章:

Python删除列表的重叠

python-3.x - 在 CANbus 上接收消息总是返回与 python-can 相同的值

python - 权限错误 : [WinError 5] Access is denied

opencv - 相机系统的真正起源在哪里?

c++ - 使用深度图

python - TypeError : string indices must be integers, not str with JSON 解析

python - 使用 np.unique 从 2 个 numpy 数组中删除成对重复项

python - 查找用于连接到我的套接字服务器的主机名

python - Mysql似乎无法识别Python中的WHERE语句

java - 我是否正确访问文件?