Beispiel #1
0
 def similarity_mode_2(self, image1, image2):
     """
     直方图的距离计算
     :param image1: 
     :param image2: 
     :return: 
     """
     # 预处理
     img1 = image1.resize((256, 256)).convert('RGB')
     img2 = image2.resize((256, 256)).convert('RGB')
     sim = image_similarity_fundimental.difference(img1.histogram(),
                                                   img2.histogram())
     return sim
Beispiel #2
0
 def similarity_mode_3(self, image1, image2):
     """
     感知哈希算法
     :param image1: 
     :param image2: 
     :return: 
     """
     # 如果是frame的话,可以直接使用
     # img = cv2.resize(frame, (8, 8))
     img1 = image1.resize((128, 128)).convert('1')
     img2 = image2.resize((128, 128)).convert('1')
     hist1 = list(img1.getdata())
     hist2 = list(img2.getdata())
     sim = image_similarity_fundimental.difference(hist1, hist2)
     return sim
Beispiel #3
0
 def similarity_mode_1(self, image1, image2):
     """
     分块直方图的距离计算
     :param image1: 
     :param image2: 
     :return: 
     """
     sum = 0
     img1 = image1.resize((256, 256)).convert('RGB')
     img2 = image2.resize((256, 256)).convert('RGB')
     for i in range(4):
         for j in range(4):
             hist1 = img1.crop((i * 64, j * 64, i * 64 + 63,
                                j * 64 + 63)).copy().histogram()
             hist2 = img2.crop((i * 64, j * 64, i * 64 + 63,
                                j * 64 + 63)).copy().histogram()
             sum += image_similarity_fundimental.difference(hist1, hist2)
             # print difference(hist1, hist2)
     return sum / 16
Beispiel #4
0
 def similary_calculate(self, img1, img2):
     hist1 = list(img1.getdata())
     hist2 = list(img2.getdata())
     return image_similarity_fundimental.difference(hist1, hist2)