def __init__(self, token, ip): self.ip = ip # TODO: Set this threshold to whatever you want self.temperature_threshold_C = 38.5 # In degrees C # Initialize the trueface SDK using hte lite model # We will be using facial recognition to ensure we only send 1 notification per identity # So that if a sick person stands infront of the camera, we only send 1 notification and not countless options = tfsdk.ConfigurationOptions() options.fr_model = tfsdk.FACIALRECOGNITIONMODEL.LITE self.sdk = tfsdk.SDK(options) is_valid = self.sdk.set_license(token) if (is_valid == False): print("Invalid License Provided") quit() self.faceprint = {} # Set up email stuff # For this demo, we will be using the gmail smtp server self.port = 465 # For SSL self.smtp_server = "smtp.gmail.com" # TODO: Enter the sender gmail account # "Allow less secure apps" must be turned ON https://myaccount.google.com/lesssecureapps self.sender_email = "*****@*****.**" # TODO: Enter the recipient address self.receiver_email = "*****@*****.**" # TODO: Enter your gmail account password (corresponding to the sender_email account) self.password = "******"
def __init__(self, token, ip): self.ip = ip # TODO: Set this threshold to whatever you want self.temperature_threshold_C = 38.5 # In degrees C # Initialize the trueface SDK using hte lite model # We will be using facial recognition to ensure we only send 1 notification per identity # So that if a sick person stands infront of the camera, we only send 1 notification and not countless options = tfsdk.ConfigurationOptions() options.fr_model = tfsdk.FACIALRECOGNITIONMODEL.LITE self.sdk = tfsdk.SDK(options) is_valid = self.sdk.set_license(token) if (is_valid == False): print("Invalid License Provided") quit() self.faceprint = {} # Set up text message stuff # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACe275517637075b7fb777f44f7b549efc' auth_token = 'your_auth_token' self.client = Client(account_sid, auth_token) self.from_number = '+15017122661' self.to_number = '+15558675310'
def usage(): print("Usage: {} <collection folder name> <input video filename>".format( sys.argv[0])) if len(sys.argv) != 3: usage() sys.exit(1) collection_folder = sys.argv[1] filepath = sys.argv[2] if filepath.isdigit(): filepath = int(filepath) options = tfsdk.ConfigurationOptions() # Can set configuration options here # ex: #options.smallest_face_height = -1 options.fd_mode = tfsdk.FACEDETECTIONMODE.VERSATILE # options.fd_filter = tfsdk.FACEDETECTIONFILTER.BALANCED options.fr_model = tfsdk.FACIALRECOGNITIONMODEL.FULL options.models_path = '/home/seelaman/Workspace/trueface/trueface.base/tfsdk_python3.7.gpu/trueface_sdk' options.dbms = tfsdk.DATABASEMANAGEMENTSYSTEM.SQLITE # Use the accurate object detector #options.obj_model = tfsdk.OBJECTDETECTIONMODEL.ACCURATE sdk = tfsdk.SDK(options) # TODO: replace the string with your license code.
def identifyTemplate(self, templateQueue, token): # Initialize the trueface SDK # Be sure to use the same SDK options as the camera # Since we will be using the GET /fr-template-lite endpoint, we will initialize the SDK using the lite model options = tfsdk.ConfigurationOptions() options.fr_model = tfsdk.FACIALRECOGNITIONMODEL.LITE options.dbms = tfsdk.DATABASEMANAGEMENTSYSTEM.NONE # We will NOT be writing template to disk for this demo. options.smallest_face_height = -1 # https://reference.trueface.ai/cpp/dev/latest/py/general.html#tfsdk.ConfigurationOptions sdk = tfsdk.SDK(options) is_valid = sdk.set_license(token) if (is_valid == False): print("Invalid License Provided") quit() # At this point, we can either load an existing trueface database & collection, or create a new one and populate it with data # For the sake of this demo, we will create a new collection (memory only, meaning data will not persist after app shuts down) # If we are using a database backend, need to first call create_database_connection # Since we are using DATABASEMANAGEMENTSYSTEM.NONE this is not necessary # For more aobut 1 to N, please refer to: https://reference.trueface.ai/cpp/dev/latest/usage/identification.html # Create a new collection res = sdk.create_load_collection("my_collection") if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to create collection") quit() # Some identities to populate into our collection # TODO: Can add images of yourself here image_identities = [ ("../../cpp_sdk/images/armstrong/armstrong1.jpg", "Armstrong"), ("../../cpp_sdk/images/armstrong/armstrong2.jpg", "Armstrong"), # Can add the same identity more than once ("../../cpp_sdk/images/obama/obama1.jpg", "Obama") ] # Generate templates, enroll in our collection for path, identity in image_identities: print("Processing image:", path, "with identity:", identity) # Generate a template for each image res = sdk.set_image(path) if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to set image at path:", path) continue # Detect the largest face in the image found, faceBoxAndLandmarks = sdk.detect_largest_face() if found == False: print("No face detected in image:", path) continue # We want to only enroll high quality images into the database / collection # Therefore, ensure that the face height is at least 100px faceHeight = faceBoxAndLandmarks.bottom_right.y - faceBoxAndLandmarks.top_left.y print("Face height:", faceHeight, "pixels") if faceHeight < 100: print("The face is too small in the image for a high quality enrollment.") continue # Get the aligned chip so we can compute the image quality face = sdk.extract_aligned_face(faceBoxAndLandmarks) # Compute the image quality score res, quality = sdk.estimate_face_image_quality(face) if (res != tfsdk.ERRORCODE.NO_ERROR): print("There was an error computing the image quality") continue # Ensure the image quality is above a threshold (TODO: adjust this threshold based on your use case). print("Face quality:", quality) if quality < 0.8: print("The image quality is too poor for enrollment") continue # As a final check, we can check the orientation of the head and ensure that it is facing forward # To see the effect of yaw and pitch on match score, refer to: https://reference.trueface.ai/cpp/dev/latest/py/face.html#tfsdk.SDK.estimate_head_orientation res, yaw, pitch, roll = sdk.estimate_head_orientation(faceBoxAndLandmarks) if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to compute head orientation") print("Head orientation, Yaw:", yaw * 180 / 3.14, ", Pitch:", pitch * 180 / 3.14, ", Roll:", roll * 180 / 3.14, "degrees") # TODO: Can filter out images with extreme yaw and pitch here # Now that we have confirmed the images are high quality, generate a template from that image res, faceprint = sdk.get_face_feature_vector(face) if (res != tfsdk.ERRORCODE.NO_ERROR): print("There was an error generating the faceprint") continue # Enroll the feature vector into the collection res, UUID = sdk.enroll_template(faceprint, identity) if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to enroll feature vector") continue # TODO: Can store the UUID for later use print("Success, enrolled template with UUID:", UUID) print("--------------------------------------------") while True: # TODO: If the queue get's too backed up, can remove some items without processing template = templateQueue.get() errorcode, probe_faceprint = tfsdk.SDK.json_to_faceprint(template) if (errorcode != tfsdk.ERRORCODE.NO_ERROR): print("There was an error decoding the json to a faceprint") continue # Now run 1 to N identification ret_code, found, candidate = sdk.identify_top_candidate(probe_faceprint) if ret_code != tfsdk.ERRORCODE.NO_ERROR: print("Something went wrong!") elif found == True: print("Found match with identity:", candidate.identity) print("Match probability:", candidate.match_probability) else: print("Unable to find match") print(" ")
def __init__(self, token, ip): self.ip = ip # Initialize the trueface SDK # Be sure to use the same SDK options as the camera # Since we will be using the GET /fr-template-lite endpoint, we will initialize the SDK using the lite model options = tfsdk.ConfigurationOptions() options.fr_model = tfsdk.FACIALRECOGNITIONMODEL.LITE options.dbms = tfsdk.DATABASEMANAGEMENTSYSTEM.NONE # We will NOT be writing template to disk for this demo. options.smallest_face_height = -1 # https://reference.trueface.ai/cpp/dev/latest/py/general.html#tfsdk.ConfigurationOptions self.sdk = tfsdk.SDK(options) is_valid = self.sdk.set_license(token) if (is_valid == False): print("Invalid License Provided") quit() # At this point, we can either load an existing trueface database & collection, or create a new one and populate it with data # For the sake of this demo, we will create a new collection (memory only, meaning data will not persist after app shuts down) # If we are using a database backend, need to first call create_database_connection # Since we are using DATABASEMANAGEMENTSYSTEM.NONE this is not necessary # For more aobut 1 to N, please refer to: https://reference.trueface.ai/cpp/dev/latest/usage/identification.html # Create a new collection res = self.sdk.create_load_collection("my_collection") if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to create collection") quit() # Some identities to populate into our collection # TODO: Can add images of yourself here image_identities = [ ("../../cpp_sdk/images/armstrong/armstrong1.jpg", "Armstrong"), ("../../cpp_sdk/images/armstrong/armstrong2.jpg", "Armstrong"), # Can add the same identity more than once ("../../cpp_sdk/images/obama/obama1.jpg", "Obama") ] # Generate templates, enroll in our collection for path, identity in image_identities: # Generate a template for each image res = self.sdk.set_image(path) if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to set image at path:", path) quit() # Extract the feature vector res, v = self.sdk.get_largest_face_feature_vector() if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to generate feature vector") quit() # Enroll the feature vector into the collection res, UUID = self.sdk.enroll_template(v, identity) if (res != tfsdk.ERRORCODE.NO_ERROR): print("Unable to enroll feature vector") quit() # TODO: Can store the UUID for later use print("Success, enrolled template with UUID:", UUID)