没有合适的资源?快使用搜索试试~ 我知道了~
python opencv 图片相似度对比
5星 · 超过95%的资源 需积分: 18 11 下载量 62 浏览量
2023-02-08
16:09:10
上传
评论
收藏 301KB PDF 举报
温馨提示
试读
5页
python opencv 图片相似度对比
资源推荐
资源详情
资源评论
⽤⽤python实现对⽐两张图⽚的不同实现对⽐两张图⽚的不同
from PIL import Image
from PIL import ImageChops
def compare_images(path_one, path_two, diff_save_location):
"""
⽐较图⽚,如果有不同则⽣成展⽰不同的图⽚
@参数⼀: path_one: 第⼀张图⽚的路径
@参数⼆: path_two: 第⼆张图⽚的路径
@参数三: diff_save_location: 不同图的保存路径
"""
image_one = Image.open(path_one)
image_two = Image.open(path_two)
try:
diff = ImageChops.difference(image_one, image_two)
if diff.getbbox() is None:
# 图⽚间没有任何不同则直接退出
print("【+】We are the same!")
else:
diff.save(diff_save_location)
except ValueError as e:
text = ("表⽰图⽚⼤⼩和box对应的宽度不⼀致,参考API说明:Pastes another image into this image."
"The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, "
"right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted "
"image must match the size of the region.使⽤2纬的box避免上述问题")
print("【{0}】{1}".format(e,text))
if __name__ == '__main__':
compare_images('1.png',
'2.png',
'我们不⼀样.png')
执⾏结果:
z18502802576
- 粉丝: 0
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页