我正在迭代一个大的选择,并在这些图像上执行任务选择。循环不会中断,但当需要访问图像时,该变量将返回None。我试图确定是什么使镜像不兼容,但我做不到。我的问题是,当图像无法加载到OpenCV中时,如何检索某种形式的回溯?更普遍的是,镜像必须满足的兼容性参数是什么,以及如何测试它们?
下面是我的代码片段:
images = []
image_names = []
for image in os.listdir('images'):
print image
images.append(cv2.imread('images\\' + image, 1))
image_names.append(image)
x = 0
while x < len(images):
print x
print image_names[x]
print images[x].mean() # it breaks here with image[x] being None
x += 1 # so the problem must be where the image is opened文档中明确指出,如果imread()方法无法打开,它将不会报告错误,只会返回None。然后我可以只测试这个,并排除这个图像,但它被证明是许多他们,所以我想纠正这个问题。
发布于 2015-02-12 22:42:41
“所以问题一定是在图像打开的地方”--没错!
for image in os.listdir('images'):
print image
im = cv2.imread('images\\' + image, 1)
if im != None:
images.append(im)
image_names.append(image)
else:
print "invalid:", imagehttps://stackoverflow.com/questions/28479617
复制相似问题