我的数据库中有一些图片的网址,我想将它们与本地的图片进行比较,而不需要下载它们。
我读过这个例子和这个问题,我试过这个
adr = "url_of_image"
file = cStringIO.StringIO(urllib.urlopen(adr).read())
img = Image.open(file)
img = str(img)
print type(img)
image_file = open('adresse_of_image_in_local').read()
print type(image_file)
if ( img == image_file):
print "the pictures of the same"
else :
print "they are not the same"我测试了相同图像的代码,但是我得到了这个
<type 'str'>
<type 'str'>
they are not the same我的问题是,如何在不保存的情况下,将本地图像与web图像进行比较?
发布于 2017-09-20 18:30:29
您不能避免从网络下载图像,否则您将没有什么可比较的。但是,如果无法写入磁盘,则可以将其完全下载到RAM中。这就是你已经正确地做了的。
但是,图像对象上的==不能工作。也试着在你的本地形象上做Image.open()。然后比较两种情况下.getbbox()返回的内容。如果大小匹配,请尝试比较.tobytes()返回的内容。
https://stackoverflow.com/questions/46328576
复制相似问题