Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Gaze Detection/caught/suspect_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gaze Detection/caught/suspect_10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gaze Detection/caught/suspect_12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Gaze Detection/caught/suspect_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Gaze Detection/caught/suspect_3.jpg
Binary file not shown.
Binary file removed Gaze Detection/caught/suspect_4.jpg
Binary file not shown.
Binary file added Gaze Detection/caught/suspect_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions Gaze Detection/clean_up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import face_recognition
import os


# Removes duplicates of suspects
def cleanUp():
dir = "caught/"
fileCount = len(os.listdir(dir))
print("num of images: " + str(fileCount))
if(os.path.exists(dir + "suspect_1.jpg")):
# Adds suspect_1 to the individual suspects array
suspect1 = face_recognition.load_image_file(dir + "suspect_1.jpg")
suspect1Encoding = face_recognition.face_encodings(suspect1)[0]
individual_suspects = [suspect1Encoding]
i=2
# Iterates from suspect_2 to the last suspect
for suspects in range(2,fileCount+1):
image,i = loadNextImage(i)
try:
imageEncoding = face_recognition.face_encodings(image)[0]
except IndexError:
print("there are no detected faces")
i+=1
continue
# results is a boolean array that compares the encoding with each individual suspect
results = face_recognition.compare_faces(individual_suspects, imageEncoding)
if(not True in results):
# suspect is a new individual and is added to the array
individual_suspects.append(imageEncoding)
else:
os.remove(dir + "suspect_" + str(i)+ ".jpg")
print("suspect_" + str(i) + " was removed")
i+=1
numIndividualSuspects = len(individual_suspects)
print("num of individual suspects: " + str(numIndividualSuspects))
else:
return

# Gets the next valid image
# i is the index of the next valid image
def loadNextImage(j):
i=j
while os.path.exists(dir):
try:
image = face_recognition.load_image_file(dir + "suspect_" + str(i) +".jpg")
return image,i
except FileNotFoundError:
i+=1
continue

cleanUp()
23 changes: 23 additions & 0 deletions Gaze Detection/real_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
solid = True
initial = True

# Checks if a face encoding exists in current known face encodings
def checkDupe(face_encoding):
results = face_recognition.compare_faces(known_face_encodings, face_encoding)
if(not True in results):
return False
else:
return True

#We will only anylyze every 5 frames facial features
frame_count = 0

Expand Down Expand Up @@ -106,6 +114,21 @@
known_face_encodings.append(suspect_face_encoding)
known_face_names.append("SUSPECT_" + str(suspect_num))

if(len(face_recognition.face_encodings(suspect_image)) != 0):
suspect_face_encoding = face_recognition.face_encodings(suspect_image)[0]
# Removes frame from storage if encoding returns duplicate
if(checkDupe(suspect_face_encoding)):
print("captured frame is a duplicate. Removing...")
os.remove(storage + "/suspect_" + str(suspect_num) + ".jpg")
suspect_num -= 1
continue
#Initialize suspition level
suspicion_levels.append(0)
print("Suspect priorities: "+ str(suspicion_levels))
#add it to list of known faces
known_face_encodings.append(suspect_face_encoding)
known_face_names.append("SUSPECT_" + str(suspect_num))
print("suspect_" + str(suspect_num) + " detected")

face_names.append(name)

Expand Down
11 changes: 11 additions & 0 deletions Gaze Detection/server.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Gaze Detection Server</title>
</head>
<body>
<h1>Most Recent Suspect</h1>
<img src="/caught/suspect_1.jpg" alt="" width="250" height="250" />
</body>
</html>
18 changes: 18 additions & 0 deletions Gaze Detection/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from http.server import HTTPServer, SimpleHTTPRequestHandler

class Server(SimpleHTTPRequestHandler):

def do_get(self):
if self.path == '/':
self.path = '/index.html'
try:
file_to_open = open(self.path[1:]).read()
self.send_response(200)
except:
file_to_open = "File Not Found"
self.send_response(404)
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))

httpd = HTTPServer(('localhost', 8080), Server)
httpd.serve_forever()