-
Notifications
You must be signed in to change notification settings - Fork 2
/
faceMatch
94 lines (65 loc) · 3.6 KB
/
faceMatch
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
import smtplib
from email.mime.image import MIMEImage
from datetime import datetime
from email.mime.multipart import MIMEMultipart
import traceback
import face_recognition
import pickle
import os
class FaceMatch:
def doFaceMatch():
known_encodings=[]
imagesNames=os.listdir("/home/dark/Programing/Major/ImageToText")
a=[]
for name in imagesNames:
textFileName="/home/dark/Programing/Major/ImageToText/"+name
with open (textFileName,"rb") as fp:
a=pickle.load(fp)
unknownImages=os.listdir("/home/dark/Programing/Major/Down_Images")
for name2 in unknownImages:
image_to_test = face_recognition.load_image_file("/home/dark/Programing/Major/Down_Images/"+name2)
try:
image_to_test_encoding = face_recognition.face_encodings(image_to_test)[0]
except Exception as e:
continue
face_distances = face_recognition.face_distance(a, image_to_test_encoding)
percentage=(1-face_distances)*100
if(percentage>50):
print("*"*15)
print("Image stored in our Database : "+name+"\nImage retrived from camera : "+name2)
print("Match percent : "+str(percentage)+"%")
print("*"*15)
############# Mail Sending Block ############################
f_time = datetime.now().strftime('%a %d %b @ %H:%M')
toaddr = '[email protected]' # redacted
me = '[email protected]' # redacted
subject = 'Photo ' + f_time
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "Photo @ " + f_time
########## Image from Street CAM ################
fp = open('/home/dark/Programing/Major/Down_Images/'+name2, 'rb')
img = MIMEImage(fp.read(),name=name2)
fp.close()
msg.attach(img)
########## Image from Street CAM ################
########## Image from Known Database ################
temp=name[0:-4]
fp = open('/home/dark/Programing/Major/KnownImages/'+temp, 'rb')
img2 = MIMEImage(fp.read(),name=temp)
fp.close()
msg.attach(img2)
########## Image from Known Database ################
try:
s = smtplib.SMTP(host='smtp.gmail.com', port=587)
s.ehlo()
s.starttls()
s.ehlo()
s.login("gmail-id","password") #Enter a gmail account in place of "gmail-id" and password at "password"
s.send_message(msg)
s.quit()
except:
traceback.print_exc()
############# Mail Sending Block ############################