When implementing some function processing functions, sometimes batch images are processed, and the processed images are expected to be passed to another function for processing, and multiple images are used as return values. A list is required to store these images as parameters and pass them to another function. a function.
When I first checked this on the Internet, I saw that it was, images = [[], []] * images_num
but there was always an error in the final output TypeError: Expected Ptr<cv::UMat> for argument 'mat'
. Check the output of the images list, the empty list
List after saving image data
The image is stored in matrix mode, images = [[]]*images_num
just set the list as directly.
def f1():
images = [[]] * images_num
for i in range images_num:
# 此处省略处理过程,img为处理后的图像
images[i] = img
return images
All functions can be temporarily stored in a list as return values. If you put return in the for loop, only the first image data will be returned.
def f2():
# 调用函数f1
images = f1()
# 显示图像,可以直接使用imshow函数,不需要使用imread读取
for img in images:
cv2.imshow(‘img’, img)
cv2.waitKey(100)