示例#1
0
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
示例#2
0
def reset_training():
    PersonGroup.reset_all()
    for face_document in new_faces.find():
        person = PersonLegacy(new_faces, face_document)
        person.remove_all_trained_details()

    flash('Reset all training group', category='info')
    return redirect('/')
示例#3
0
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('/')
示例#4
0
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})
示例#5
0
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("/")
示例#6
0
def get_face_image(object_id):
    person = PersonLegacy.fetch(new_faces, object_id)
    return Response(person.image, mimetype='image/jpeg')
示例#7
0
def is_face_ignored(object_id):
    person = PersonLegacy.fetch(new_faces, object_id)
    return jsonify({'result': person.get_group_person_id(IGNORE_PERSON_GROUP)})
示例#8
0
def is_face_unknown(object_id):
    person = PersonLegacy.fetch(new_faces, object_id)
    return jsonify(
        {'result': person.get_group_person_id(UNKNOWN_PERSON_GROUP)})
示例#9
0
def person_info(object_id):
    person = PersonLegacy.fetch(new_faces, object_id)
    return jsonify(person.document)