def deletar(name): all_face_encodings = {} pickle_file = 'dataset_faces.pickle' try: all_face_encodings = pickle.load(pickle_file) except: print("Arquivo vazio") try: all_face_encodings.pop(name) pickle.safe_dump(all_face_encodings, pickle_file) print("Depois : " + str(all_face_encodings)) except: return "Ocorreu um erro ao salvar os dados" return "Usuário removido com sucesso."
def atualizar(file, name): all_face_encodings = {} pickle_file = 'dataset_faces.pickle' load_image = face_recognition.load_image_file(file) image_encoding = face_recognition.face_encodings(load_image)[0] try: all_face_encodings = pickle.load(pickle_file) except: print("Arquivo vazio") try: all_face_encodings[name] = image_encoding pickle.safe_dump(all_face_encodings, pickle_file) except: raise return "Ocorreu um erro ao salvar os dados" return "Foto atualizada com sucesso"
def cadastrar(file, name): all_face_encodings = {} pickle_file = 'dataset_faces.pickle' load_image = face_recognition.load_image_file(file) image_encoding = face_recognition.face_encodings(load_image)[0] try: all_face_encodings = pickle.load(pickle_file) except: print("Arquivo vazio") print("Depois : " + str(all_face_encodings)) try: all_face_encodings[name] = image_encoding pickle.safe_dump(all_face_encodings, pickle_file) except: raise return "Ocorreu um erro ao salvar os dados" return image_encoding
def procurar(file): print("TIPO :::::: ") print(type(file)) # Load face encodings all_face_encodings = {} pickle_file = 'dataset_faces.pickle' erro = "" try: all_face_encodings = pickle.load(pickle_file) print(all_face_encodings) if all_face_encodings: print(all_face_encodings.keys()) else: erro = "Ninguem Cadastrado" except: erro = "Não foi possivel acessar o banco de dados" return erro # Grab the list of names and the list of encodings face_names = list(all_face_encodings.keys()) print("FACE NAMES") print(face_names) face_encodings = np.array(list(all_face_encodings.values())) # Try comparing an unknown image unknown_image = face_recognition.load_image_file(file) #unknown_image = file unknown_face = face_recognition.face_encodings(unknown_image) result = face_recognition.compare_faces(face_encodings, unknown_face) # Print the result as a list of names with True/False names_with_result = dict(zip(result, face_names)) if True in names_with_result.keys(): return names_with_result[True] return "Não encontrou ninguém"
def test_compress(): """Test whether data compression is working. """ pk.safe_dump({"value": 1}, path_gz, enable_verbose=False) assert pk.load(path_gz, enable_verbose=False) == {"value": 1} os.remove(path_gz)
def acesso(): # Get a reference to webcam #0 (the default one) video_capture = cv2.VideoCapture(0) # Load face encodings known_face_encodings_file = {} known_face_encodings = [] known_face_names = [] exit_msg = "404" pickle_file = 'dataset_faces.pickle' known_face_encodings_file = pickle.load(pickle_file) if known_face_encodings_file: print(known_face_encodings_file.keys()) known_face_encodings = list(known_face_encodings_file.values()) known_face_names = list(known_face_encodings_file.keys()) else: return "Ninguem cadastrado" achou = 0 # Initialize some variables face_locations = [] face_encodings = [] face_names = [] process_this_frame = True name = "" #temporizador tstart = time.process_time() while True: # Grab a single frame of video ret, frame = video_capture.read() # Resize frame of video to 1/4 size for faster face recognition processing small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) rgb_small_frame = small_frame[:, :, ::-1] # Only process every other frame of video to save time if process_this_frame: # Find all the faces and face encodings in the current frame of video face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings( rgb_small_frame, face_locations) face_names = [] for face_encoding in face_encodings: # See if the face is a match for the known face(s) matches = face_recognition.compare_faces( known_face_encodings, face_encoding) name = "Unknown" # Or instead, use the known face with the smallest distance to the new face face_distances = face_recognition.face_distance( known_face_encodings, face_encoding) best_match_index = np.argmin(face_distances) if matches[best_match_index]: name = known_face_names[best_match_index] exit_msg = name achou = 1 #chamar o arduino face_names.append(name) process_this_frame = not process_this_frame # Display the results for (top, right, bottom, left), name in zip(face_locations, face_names): # Scale back up face locations since the frame we detected in was scaled to 1/4 size top *= 4 right *= 4 bottom *= 4 left *= 4 # Draw a box around the face cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) # Draw a label with a name below the face 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) # Display the resulting image cv2.imshow('Video', frame) # Hit 'q' on the keyboard to quit! tstop = time.process_time() if (achou == 1 or (tstop - tstart) > 5): video_capture.release() cv2.destroyAllWindows() return exit_msg