-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdetect_f.py
131 lines (123 loc) · 5.3 KB
/
detect_f.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
import face_recognition
import cv2
import MySQLdb
from datetime import datetime
from time import gmtime, strftime
from twilio.rest import Client
import sys,os
import zulip
pokermsg=[]
name=""
def db(name):
global imgname,last_case,last_link,last_case,last_date
db=MySQLdb.connect(host="localhost",user="root",password="amit",db="rajasthan")
cur=db.cursor()
query="select * from criminal_record where cname='"+name+"';"
cur.execute(query)
for row in cur.fetchall():
imgname=row[1]
last_case=row[2]
last_date=row[3]
last_link=row[4]
print(imgname,last_case,last_link,last_date)
db.close()
def culprit_match():
f=0
k=0
global pokermsg,name
global imgname,last_case,last_link,last_case,last_date
video_capture = cv2.VideoCapture(0)
Picture_face_encoding=[]
Pic_image1 = face_recognition.load_image_file("Amit.jpeg")
Pic_face_encoding1 = face_recognition.face_encodings(Pic_image1)[0]
Pic_image2 = face_recognition.load_image_file("Debashish.jpg")
Pic_face_encoding2 = face_recognition.face_encodings(Pic_image2)[0]
# Pic_image3 = face_recognition.load_image_file("Kamal.jpg")
# Pic_face_encoding3 = face_recognition.face_encodings(Pic_image3)[0]
# Pic_image4 = face_recognition.load_image_file("Soumyajit.jpg")
# Pic_face_encoding4 = face_recognition.face_encodings(Pic_image4)[0]
# Pic_image5 = face_recognition.load_image_file("Rohit.png")
# Pic_face_encoding5 = face_recognition.face_encodings(Pic_image5)[0]
face_locations = []
known_face_encodings = [Pic_face_encoding1,Pic_face_encoding2]#Pic_face_encoding3,Pic_face_encoding4,Pic_face_encoding5,
known_face_names = ["Amit Singh","Debashish Bhol"]#Pic_face_encoding3,Pic_face_encoding4,Pic_face_encoding5,
face_names=[]
face_encodings=[]
process_this_frame = True
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
if process_this_frame:
face_locations = face_recognition.face_locations(small_frame)
face_encodings = face_recognition.face_encodings(small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
match = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
if True in match:
f_index=match.index(True)
name=known_face_names[f_index]
print(match)
print(name)
db(name)
f=1
msg="Culprit Found. Details are here. Name - "+name+" and Criminal Case is "+last_case+" Dated - "+str(last_date)
print(msg)
pokermsg.append(msg)
face_names.append(name)
k+=1
process_this_frame = not process_this_frame
for (top, right, bottom, left), name in zip(face_locations, face_names):
top *= 4
right *= 4
bottom *= 4
left *= 4
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
cv2.imshow('Video', frame)
print(k)
if (cv2.waitKey(1) & 0xFF == ord('q')) or k==100:
k=0
print(k)
break
video_capture.release()
cv2.destroyAllWindows()
return f
imgname=""
last_case=""
last_link=""
last_case=""
last_date=""
msg=""
prodo=0
k=0
k=culprit_match()
pokermsg=list(set(pokermsg))
print("Deal")
print(imgname,last_case,last_link,last_date)
print(msg)
if k==1:
print(msg)
msg="Culprit Found. Details are here. Name - "+name+" and Criminal Case is "+last_case+" Dated - "+str(last_date)
f=open("Speech21.vbs","w")
k="Dim sapi \nSet sapi=Createobject(\"sapi.spvoice\") \nsapi.Speak "+'"'+pokermsg[0]+'"'
f.write(k)
f.close()
os.system("Speech21.vbs")
zulip_client = zulip.Client(email="[email protected]", client="MyTestClient/0.1",config_file="C:\\Users\\tusha\\.zuliprc")
message = {"type": "stream","to": ["general"],"subject": "your subject","content": msg}
print(zulip_client.send_message(message))
print("Message Sent")
else:
msg="Culprit Not Found. There are no criminal record of the current detected person."
f=open("Speech21.vbs","w")
k="Dim sapi \nSet sapi=Createobject(\"sapi.spvoice\") \nsapi.Speak "+'"'+msg+'"'
f.write(k)
f.close()
os.system("Speech21.vbs")
zulip_client = zulip.Client(email="[email protected]", client="MyTestClient/0.1",config_file="C:\\Users\\tusha\\.zuliprc")
message = {"type": "stream","to": ["general"],"subject": "your subject","content": msg}
print(zulip_client.send_message(message))
print("Message Sent")