使用Wand(Python)进行图像识别

2024-05-23 22:37:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在实现一个Python脚本来检查两个图像之间的相似性。我被迫使用Imagemagick,所以我选择使用Wand作为Python库。我的工作流程是这样的:

from wand.image import Image

img1 = Image(filename='/path/to/first/image')
img2 = Image(filename='/path/to/second/image')

# Normalize the two images in order to avoid exposition-related issues
img1.normalize()
img2.normalize()

# Create a 64 x 64 thumbnail for every image
img1.resize(64, 64)
img2.resize(64, 64)

# Compare the two images using root mean square metric
comparison = img1.compare(img1, metric='root_mean_square')[1]

通常这种方法(均方根)为非常相似的图像提供0.0的值,对于相似的图像,>;=0.1;对于不相似的图像,>;=0.5。我的问题是:使用这个工具比较两个图像是否是一个好方法?有更好的方法吗?有更好的衡量标准吗?在


Tags: thetopath方法图像imagerootfilename