我有以下代码可以比较两个图像:
path_one = filedialog.askopenfilename()
path_two = ("D:/QUIZ/folder1/folder2/1101Def.bmp")
image_one = Image.open(path_one)
image_two = Image.open(path_two)
diff = ImageChops.difference(image_one, image_two)
if diff.getbbox():
print("images are different")
else:
print("images are the same")
这个简单的代码可以正常工作。
现在,我尝试拍摄第一张图像,并检查包含数千张图像的文件夹中是否有一个相似的图像。
为此,我使用glob将所有图像名称存储在列表中,然后尝试以这种方式进行迭代:
imagelist = []
os.chdir("i_denti")
for file in glob.glob("*.bmp"):
listaimagens.append(file)
for x in imagelist:
print(x)
path_two = ("D:/QUIZ/folder1/folder2/"+str(x))
image_two = Image.open(path_two)
diff = ImageChops.difference(image_one, image_two)
if diff.getbbox():
print("a imagem "+str(x)+" é diferente")
else:
print("a imagem "+str(x)+" é a correcta")
return image1._new(image1.im.chop_difference(image2.im))
使用此代码,我遇到了错误
ValueError: images do not match
任何人都可以帮助我,并说为什么代码无法在for循环内工作?