def simulate_tracking(): while True: for tracking_data_item in sample_tracking_data: # Pause simulation is requested while stop_simulating.is_set(): pass # Format the data according to its source data_to_send = "" if args.source is not None: if args.source.lower() == 'stanford': data_to_send = DataFormatter.format_stanford( tracking_data_item) elif args.source.lower() == 'cornell': data_to_send = DataFormatter.format_cornell( tracking_data_item) else: data_to_send = tracking_data_item else: data_to_send = tracking_data_item # Send the data to the server if data_to_send != "": Messaging.send(MSG_TO_SERVER_KEYS.TRACKING_DATA.name, data_to_send) time.sleep(.05)
def sendfaceid(socket, image_base64): imagedata = image.b64decode(image_base64) rgb_small_frame = image.get_rgb_small_frame(imagedata) face_locations, ids, face_landmarks = FaceRecognizer.recognize( rgb_small_frame) jsonstring = json.dumps({'face_locations': face_locations, 'ids': ids}) messaging.send(socket, codes.dataformats.STRING, jsonstring)
def get_all_faces_data(): messaging.send(messaging.req, codes.dataformats.MULTIPART, [[reqintents.INTENT_REQ_ALL_FACES_DATA], b'']) json_faces_data = messaging.receive(messaging.req, codes.dataformats.STRING) faces_data = json.loads(json_faces_data) return faces_data
if data_to_send != "": Messaging.send(MSG_TO_SERVER_KEYS.TRACKING_DATA.name, data_to_send) time.sleep(.05) simulation_thread = threading.Thread(target=simulate_tracking) simulation_thread.start() # Run the program from the terminal while (True): input_key = input( "Press q to quit, t to start the tracking simulation and p to pause the simulation...\n" ).strip() if input_key == "q": stop_simulating.set() Messaging.send(MSG_TO_SERVER_KEYS.TRACKING_LOST.name, '') print('Exiting..') os._exit(0) elif input_key == "p": stop_simulating.set() Messaging.send(MSG_TO_SERVER_KEYS.TRACKING_LOST.name, '') elif input_key == "t": if stop_simulating is not None: print('Started tracking') Messaging.send(MSG_TO_SERVER_KEYS.TRACKING_STARTED.name, '') stop_simulating.clear() else: continue
def update_faces_data(socket, faces_data): faces_data = json.loads(faces_data) load_images(faces_data) messaging.send(socket, codes.dataformats.BINARY, bytearray([0x0]))