[英]Error “TypeError: Expected Ptr<cv::UMat> for argument 'mat'” when trying to display images from an Array
I've read in all the photos from a folder into an array.我已将文件夹中的所有照片读入数组。 I'm trying to confirm that this works by displaying the first photos 5 in the array.我试图通过显示数组中的第一张照片 5 来确认这是否有效。 Here's what I've tried:这是我尝试过的:
def read_img(img_list, img):
n = cv2.imread(img, 0)
img_list.append(n)
return img_list
path = glob.glob("foo/images/*.png")
list_ = []
cv_image = [read_img(list_, img) for img in path]
for i in range(5):
cv2.imshow("images", cv_image[i])
cv2.waitKey(0)
I'm currently getting the error: cv2.imshow("images", cv_image[i]) TypeError: Expected Ptr<cv::UMat> for argument 'mat'
我目前收到错误: cv2.imshow("images", cv_image[i]) TypeError: Expected Ptr<cv::UMat> for argument 'mat'
I'm not very familiar with OpenCV and haven't found a solution online so far.我对 OpenCV 不是很熟悉,目前还没有在网上找到解决方案。 Please let me know.请告诉我。
In your for
loop, when accessing the images from your list cv_image
, you need to have another [0]
index to "enter" into the array of the read image.在您的for
循环中,当从列表cv_image
访问图像时,您需要有另一个[0]
索引才能“输入”到读取图像的数组中。 Try:尝试:
for i in range(5):
cv2.imshow("images", cv_image[i][0]) # The zero is to *dive* into the list of image arrays
cv2.waitKey(0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.