def person_identify(object_id): person = PersonLegacy.fetch(new_faces, object_id) possible_matches = [] for pg in [ PersonGroup.known_person_group(), PersonGroup.unknown_person_group(), PersonGroup.ignore_person_group() ]: identification_result = pg.identify(person) if not identification_result: continue for candidates in identification_result.values(): for candidate in candidates: person_id = candidate['personId'] matching_person = PersonLegacy.fetch_by_person_id( new_faces, person_id) if not matching_person: continue possible_matches.append(matching_person.id) time.sleep(1) if person.id not in possible_matches: possible_matches.append(person.id) return jsonify(result=possible_matches), 200
def delete_face(object_id): # TODO: Sanitize this input person = PersonLegacy.fetch(new_faces, object_id) result = person.delete() if result is None: flash('Failed deleting: {}'.format(json.dumps(result))) return redirect('/')
def is_face_known(object_id): person = PersonLegacy.fetch(new_faces, object_id) person_group_id = person.get_group_person_id(KNOWN_PERSON_GROUP) result = person_group_id is not None if not result: result = person in PersonGroup.known_person_group() return jsonify({'result': result})
def train_face(object_id, person_group): person = PersonLegacy.fetch(new_faces, object_id) try: person_group.add_person(person) except CognitiveFaceException as ex: if ex.status_code in [400, 404]: flash("Face not detected, can't add to group - " + person_group.name, category='warning') return redirect('/') except Exception as ex: flash("API Failed - {}".format(ex.message), category="danger") return redirect("/") unknown_person_group = PersonGroup.unknown_person_group() if not unknown_person_group.remove_person(person): flash("Face doesn't exist in " + unknown_person_group.name + " so it wasn't removed", category='info') return redirect("/")
def get_face_image(object_id): person = PersonLegacy.fetch(new_faces, object_id) return Response(person.image, mimetype='image/jpeg')
def is_face_ignored(object_id): person = PersonLegacy.fetch(new_faces, object_id) return jsonify({'result': person.get_group_person_id(IGNORE_PERSON_GROUP)})
def is_face_unknown(object_id): person = PersonLegacy.fetch(new_faces, object_id) return jsonify( {'result': person.get_group_person_id(UNKNOWN_PERSON_GROUP)})
def person_info(object_id): person = PersonLegacy.fetch(new_faces, object_id) return jsonify(person.document)