-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetHash.py
More file actions
45 lines (38 loc) · 1.51 KB
/
Copy pathgetHash.py
File metadata and controls
45 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# coding=utf-8
import os
import sys
import imagehash
import numpy
import queryDatabase
from PIL import Image
import psycopg2
def gatherer_perception_hash(img):
normal = Image.open(img).convert('L')
crop=normal.crop((17,37,205,150))
hash = str(imagehash.phash(crop))
return int(format(int(hash,16),'064b'))
def gatherer_simple_hash(img):
normal = Image.open(img).convert('L')
crop=normal.crop((17,37,205,150))
hash = str(imagehash.phash_simple(crop))
return int(format(int(hash,16),'064b'))
def gatherer_dhash(img):
normal = Image.open(img).convert('L')
crop=normal.crop((17,37,205,150))
hash = str(imagehash.dhash(crop))
return int(format(int(hash,16),'064b'))
def simple_hash(img):
normal = Image.open(img).convert('L')
hash = str(imagehash.phash_simple(normal))
return int(format(int(hash,16),'064b'))
def dhash(img):
normal = Image.open(img).convert('L')
hash = str(imagehash.dhash(normal))
return int(format(int(hash,16),'064b'))
def perception_hash(img):
normal = Image.open(img).convert('L')
hash = str(imagehash.phash(normal))
return int(format(int(hash,16),'064b'))
print(queryDatabase.hammingDistance(gatherer_perception_hash('real-kessig.png'),perception_hash('crop.jpg')))
print(queryDatabase.hammingDistance(gatherer_simple_hash('real-kessig.png'),simple_hash('crop.jpg')))
print(queryDatabase.hammingDistance(gatherer_dhash('real-kessig.png'),dhash('crop.jpg')))