Beispiel #1
0
 def dump_similars(self):
     rfs1 = RawFile.objects.filter(vd=self.source).filter(
         same=None).exclude(mhash=None)
     similars = Image.objects.filter(rf__in=rfs1).exclude(
         similar=None).order_by('content')
     print('similars: %d' % len(similars))
     for img in similars:
         d_p = Image.hamming_distance(img.phash, img.similar.phash)
         d_d = Image.hamming_distance(img.dhash, img.similar.dhash)
         dist = img.pd_hamming_distance(img.similar)
         if dist == IMG_PD_HDIST_THREASHOLD - 1:
             print('(%02d, %02d, %02d) : %s == %s' %
                   (dist, d_p, d_d, img.content, img.similar.content))
Beispiel #2
0
    def test_dhash_hamming_dist(self):
        id_640 = Image.compute_dhash(PIL_Image.open('image/samples/test.jpg'))
        id_256 = Image.compute_dhash(PIL_Image.open('image/samples/test_256.jpg'))
        id_480 = Image.compute_dhash(PIL_Image.open('image/samples/test_480.jpg'))
        #id_1200 = Image.compute_dhash(PIL_Image.open('image/samples/test_1200.jpg'))
        #id_org = Image.compute_dhash(PIL_Image.open('image/samples/test_org.jpg'))
        id2 = Image.compute_dhash(PIL_Image.open('image/samples/no_exif_test.jpg'))

        self.assertLessEqual(Image.hamming_distance(id_640, id_256), 0)
        self.assertLessEqual(Image.hamming_distance(id_640, id_480), 0)
        #self.assertLessEqual(Image.hamming_distance(id_640, id_1200), 0)
        #self.assertLessEqual(Image.hamming_distance(id_640, id_org), 0)
        self.assertGreater(Image.hamming_distance(id_640, id2), 3)  # distance = 15