2017-09-20 34 views
0

我在我的数据库中有一些图像的网址,我想将它们与我的本地图像进行比较而无需下载它们。如何比较本地图像和网络图像而不写?

我读this examplethis question 和我想这

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 

我的问题是如何能比的图像本地与网络上的图像没有保存?

回答

1

你不能避免从网上下载图像,否则你没有什么可比较的。您可以将它全部下载到RAM中,但是,如果您不能写入磁盘。这是你已经正确做的。

==对图像对象不起作用,但。也请在本地图片上尝试使用Image.open()。然后比较两者在.getbbox()上的回报。如果尺寸匹配,请尝试比较.tobytes()的回报。