我正在使用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/