zoukankan      html  css  js  c++  java
  • Python3 比较两个图片是否类似或相同

      Python代码

     #coding:utf8
    import os
    from PIL import Image,ImageDraw,ImageFile
    import numpy
    import pytesseract
    import cv2
    import imagehash
    import collections
    
    def compare_image_with_hash(self,image_file1="D:workpython36_crawlVeriycodemode_5246_1.png",
                                    image_file2="D:workpython36_crawlVeriycodemode_5246_2.png", max_dif=0):
            """
            max_dif: 允许最大hash差值, 越小越精确,最小为0
            推荐使用
            """
            ImageFile.LOAD_TRUNCATED_IMAGES = True
            hash_1 = None
            hash_2 = None
            with open(image_file1, 'rb') as fp:
                hash_1 = imagehash.average_hash(Image.open(fp))
                print(hash_1)
            with open(image_file2, 'rb') as fp:
                hash_2 = imagehash.average_hash(Image.open(fp))
                print(hash_2)
            dif = hash_1 - hash_2
            print(dif)
            if dif < 0:
                dif = -dif
            if dif <= max_dif:
                return True
            else:
                return False
  • 相关阅读:
    第七、八章学习笔记
    sort
    团队作业
    Linux C语言编程
    myod
    第十章学习笔记
    团队作业二—《需求分析》
    学习笔记4
    学习笔记1
    学习笔记2
  • 原文地址:https://www.cnblogs.com/shaosks/p/9711355.html
Copyright © 2011-2022 走看看