forked from sourav-coder/face-recognition-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
135 lines (107 loc) · 3.12 KB
/
test.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# testing
# from deepface import DeepFace
# v=DeepFace.verify("image/biden.jpg","image/Joe-Biden.jpg",model_name="")
# print(v)
# import face_recognition
# known_image = face_recognition.load_image_file("image/biden_2.jpg")
# unknown_image = face_recognition.load_image_file("image/Joe-Biden.jpg")
# face_locations = face_recognition.face_locations(unknown_image)
# print(face_locations)
#
# biden_encoding = face_recognition.face_encodings(known_image)[0]
# unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
#
# results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
# print(results)
# from PIL import Image,ImageOps
# import imagehash
# img1=Image.open(r"image/biden.jpg")
# img2=Image.open(r"image/biden_2.jpg")
#
# hash0 = imagehash.average_hash(img1)
# hash1 = imagehash.average_hash(img2)
#
# # check width of the images are equal or not
# if img1.width<img2.width:
# img2=img2.resize((img1.width,img1.height))
# else:
# img1=img1.resize((img2.width,img2.height))
#
# from SSIM_PIL import compare_ssim
#
#
# value = compare_ssim(img1, img2)
# print(value)
#
# cutoff = 5
#
# if hash0 - hash1 < cutoff:
# print('images are similar')
# else:
# print('images are not similar')
import imagehash
from PIL import Image
img1=Image.open(r"Unknown/test/5 new_faces.jpg")
img2=Image.open(r"Unknown/test/20 new_faces.jpg")
hash0 = imagehash.average_hash(img1)
hash1 = imagehash.average_hash(img2)
# check width of the images are equal or not
if img1.width<img2.width:
img2=img2.resize((img1.width,img1.height))
else:
img1=img1.resize((img2.width,img2.height))
from SSIM_PIL import compare_ssim
value = compare_ssim(img1, img2)
print(value)
cutoff = 5
if hash0 - hash1 < cutoff :
print('images are similar')
else:
print('images are not similar')
# cascade classifier
# import cv2
# import face_recognition
#
# face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_fullbody.xml')
# upper_body = cv2.CascadeClassifier('haarcascades/haarcascade_upperbody.xml')
#
#
# # cap = cv2.VideoCapture('samples_video/withMask.mp4')
# cap = cv2.VideoCapture(0)
# cap.set(cv2.CAP_PROP_BUFFERSIZE, 3)
#
#
#
#
# i=0
# while (cap.isOpened()):
# ret,img=cap.read()
#
# img=cv2.resize(img,(0,0),fx=0.7,fy=0.7)
# # img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
#
# landmarks=face_recognition.face_locations(img)
# print(landmarks)
# if landmarks==[]:
#
# faces = face_cascade.detectMultiScale(img,1.01,3)
# windowWidth = img.shape[1]
# windowHeight = img.shape[0]
#
# for x,y,w,h in faces:
# cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,100),2)
# j = 'Unknown/test/' + str(i) + ' new_faces' + '.jpg'
# print(w,h)
#
# if i%5==0 and (h>=windowHeight//5) and (w>=windowHeight//5) :
# print('Write :-')
# cv2.imwrite(j,img[y:y+h, x:x+w])
# i+=1
#
# cv2.imshow('video',img)
#
# if cv2.waitKey(1) & 0xFF==ord('q'):
# break
# else:
# cv2.imwrite('Unknown/test/' + str(i)+' maybe_new_faces' + '.jpg',img)
# cv2.destroyAllWindows()