当前位置:   article > 正文

深度学习 对比两张图片的差异_用python实现对比两张图片的不同

深度学习 识别两张图片的不同并标注区域
  1. from PIL import Image
  2. from PIL import ImageChops
  3. def compare_images(path_one, path_two, diff_save_location):
  4. """
  5. 比较图片,如果有不同则生成展示不同的图片
  6. @参数一: path_one: 第一张图片的路径
  7. @参数二: path_two: 第二张图片的路径
  8. @参数三: diff_save_location: 不同图的保存路径
  9. """
  10. image_one = Image.open(path_one)
  11. image_two = Image.open(path_two)
  12. try:
  13. diff = ImageChops.difference(image_one, image_two)
  14. if diff.getbbox() is None:
  15. # 图片间没有任何不同则直接退出
  16. print("【+】We are the same!")
  17. else:
  18. diff.save(diff_save_location)
  19. except ValueError as e:
  20. text = ("表示图片大小和box对应的宽度不一致,参考API说明:Pastes another image into this image."
  21. "The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, "
  22. "right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted "
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/287820
推荐阅读
相关标签
  

闽ICP备14008679号