diff --git a/Gaze Detection/caught/suspect_1.jpg b/Gaze Detection/caught/suspect_1.jpg index 96e7614..ce441ac 100644 Binary files a/Gaze Detection/caught/suspect_1.jpg and b/Gaze Detection/caught/suspect_1.jpg differ diff --git a/Gaze Detection/caught/suspect_10.jpg b/Gaze Detection/caught/suspect_10.jpg new file mode 100644 index 0000000..aedd922 Binary files /dev/null and b/Gaze Detection/caught/suspect_10.jpg differ diff --git a/Gaze Detection/caught/suspect_12.jpg b/Gaze Detection/caught/suspect_12.jpg new file mode 100644 index 0000000..9746231 Binary files /dev/null and b/Gaze Detection/caught/suspect_12.jpg differ diff --git a/Gaze Detection/caught/suspect_2.jpg b/Gaze Detection/caught/suspect_2.jpg index 4e460f0..c14b6e1 100644 Binary files a/Gaze Detection/caught/suspect_2.jpg and b/Gaze Detection/caught/suspect_2.jpg differ diff --git a/Gaze Detection/caught/suspect_3.jpg b/Gaze Detection/caught/suspect_3.jpg deleted file mode 100644 index 0b8b6fe..0000000 Binary files a/Gaze Detection/caught/suspect_3.jpg and /dev/null differ diff --git a/Gaze Detection/caught/suspect_4.jpg b/Gaze Detection/caught/suspect_4.jpg deleted file mode 100644 index 09d62ec..0000000 Binary files a/Gaze Detection/caught/suspect_4.jpg and /dev/null differ diff --git a/Gaze Detection/caught/suspect_6.jpg b/Gaze Detection/caught/suspect_6.jpg new file mode 100644 index 0000000..a297adc Binary files /dev/null and b/Gaze Detection/caught/suspect_6.jpg differ diff --git a/Gaze Detection/clean_up.py b/Gaze Detection/clean_up.py new file mode 100644 index 0000000..dcbcaa9 --- /dev/null +++ b/Gaze Detection/clean_up.py @@ -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() \ No newline at end of file diff --git a/Gaze Detection/real_time.py b/Gaze Detection/real_time.py index 4d281c5..8c66f61 100644 --- a/Gaze Detection/real_time.py +++ b/Gaze Detection/real_time.py @@ -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 @@ -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) diff --git a/Gaze Detection/server.html b/Gaze Detection/server.html new file mode 100644 index 0000000..9a4d35a --- /dev/null +++ b/Gaze Detection/server.html @@ -0,0 +1,11 @@ + + + + + Gaze Detection Server + + +

Most Recent Suspect

+ + + \ No newline at end of file diff --git a/Gaze Detection/server.py b/Gaze Detection/server.py new file mode 100644 index 0000000..47ea771 --- /dev/null +++ b/Gaze Detection/server.py @@ -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() \ No newline at end of file