Skip to content

Instantly share code, notes, and snippets.

@cyrusbehr
Last active November 23, 2020 22:38
Show Gist options
  • Save cyrusbehr/c52e307f02fca414648dc514b0dd3838 to your computer and use it in GitHub Desktop.
Save cyrusbehr/c52e307f02fca414648dc514b0dd3838 to your computer and use it in GitHub Desktop.
Sample using synchronization
@ app.route('/identify', methods=['POST'])
def identify():
# Generate the template first
# Call create_load_collection after generating template so mutex is locked for shortest amount of time
res = sdk.set_image(image_path)
res, v1 = sdk.get_largest_face_feature_vector()
# Now that we have generated the template, lock the mutex
mutex.lock()
res = sdk.create_load_collection(collection_id + '_' + namespace)
res, found, candidate = sdk.identify_top_candidate(v1, MINIMUN_RAW_IDENTIFY_THRESHOLD)
mutex.unlock()
# Now safe to ulock mutex
@ app.route('/enroll', methods=['POST'])
def enroll():
# Generate the template first
# Call create_load_collection after generating template so mutex is locked for shortest amount of time
res = sdk.set_image(image_path)
res, v1 = sdk.get_largest_face_feature_vector()
# Now that we have generated the template, lock the mutex
mutex.lock()
res = sdk.create_load_collection(collection_id + '_' + namespace)
res, UUID = sdk.enroll_template(faceprint, label)
mutex.unlock()
# Now safe to ulock mutex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment