Beispiel #1
0
def lookup_face():
    global CUSTOMER_STATUS
    global SESSION_NAME
    submitted_name = request.values.get("name")
    submitted_account = request.values.get("account")
    submitted_pin = request.values.get("pin").replace('-', '')

    frame = g_camera.get_frame(return_raw_image=True)
    vector, return_status = pfs.get_image_with_bbs(frame, 
                                                   is_mxnet=mxnet_face_model, 
                                                   return_vector=True,
                                                   classify_face=True,
                                                   customer_status=CUSTOMER_STATUS,
                                                   session_name=SESSION_NAME)
    
    collection = MongoClient(DB_HOST)[DB_NAME][COLLECTION_NAME]
    if return_status == True:
        records = list(collection.find({"name": submitted_name}))
        if not records:
            return Response("Number not found. Unable to authenticate customer.")
        record_vec = np.array(records[0]['vector']).reshape((1, 128))
        similarity = get_distances(record_vec, vector.reshape((1, 128)))
        is_similar_img =  similarity < 1.1
        is_correct_pin = records[0]["pin"] == submitted_pin
        if is_correct_pin and is_similar_img:
            CUSTOMER_STATUS = "verified"
            SESSION_NAME = submitted_name
            return Response("{0} was verified.".format(submitted_name))
        else:
            CUSTOMER_STATUS = "unverified"
            return Response("Customer not authenticated. Number Status: {0}, Facial Recognition Status: {1} -- Image similarity is {2}".format(is_correct_pin, 
                                                                                                                                            is_similar_img,
                                                                                                                                            similarity))
    no_face_detected_response = "Unable to verify identity. No face was detected."
    return Response(no_face_detected_response)
def facenet_classify_image_data(cv2_image):
    facenet_result = None
    if pk_enable_ws:
        cv2_image_string = cv2.imencode('.png', cv2_image)[1].tostring()
        response = requests.post('http://localhost:5000/get-image-with-bbs',
                                 files={'image_data': cv2_image_string})
        file_bytes = np.asarray(bytearray(response.content), dtype=np.uint8)
        facenet_result = cv2.imdecode(file_bytes, cv2.IMREAD_UNCHANGED)
    else:
        facenet_result = pfs.get_image_with_bbs(cv2_image)
    return facenet_result
Beispiel #3
0
def facenet_classify_image_data(cv2_image, docs, is_mxnet=mxnet_face_model, return_vector=False, classify_face=False, customer_status="unknown", session_name=None):
    facenet_result = None
    if pk_enable_ws:
        cv2_image_string = cv2.imencode('.png', cv2_image)[1].tostring()
        response = requests.post('http://localhost:5000/get-image-with-bbs', files={'image_data': cv2_image_string})
        file_bytes = np.asarray(bytearray(response.content), dtype=np.uint8)
        facenet_result = cv2.imdecode(file_bytes, cv2.IMREAD_UNCHANGED), False
    else:
        # print "facenet_classify_image_data: Classify Face ", classify_face
        facenet_result = pfs.get_image_with_bbs(cv2_image, docs, 
                                                is_mxnet=mxnet_face_model, 
                                                return_vector=False,
                                                classify_face=classify_face, 
                                                customer_status=customer_status,
                                                session_name=session_name)
    return facenet_result
Beispiel #4
0
def register_face():
    name = request.values.get("name")
    pin = request.values.get("pin").replace('-', '')
    frame = g_camera.get_frame(return_raw_image=True)
    print "Frame: ", frame.shape
    vector, return_status = pfs.get_image_with_bbs(frame, is_mxnet=mxnet_face_model, return_vector=True)
    print vector.shape, return_status
    collection = MongoClient(DB_HOST)[DB_NAME][COLLECTION_NAME]
    if return_status == True:
        new_doc = {"name": name,
                   "vector": vector.tolist(),
                   "pin": pin}
        collection.update_many({"name":name}, 
                               {"$set": {"pin":pin,
                                         "vector": vector.tolist()}}, upsert=True)  
        return Response("{0} added to records.".format(name))    
    return Response("Unable to locate a face in the camera. Try another perspective.".format(name))
Beispiel #5
0
def fl_get_image_with_bbs():
    # This returns an image with bbs superimposed on it
    if "image_url" in request.form.keys() and request.form['image_url']:
        image_url = request.form['image_url']
        image_data = urllib.urlopen(image_url, context=gcontext).read()
    else:
        image_data = request.files['image_data'].read()
    file_bytes = np.asarray(bytearray(image_data), dtype=np.uint8)
    cv2_image = cv2.imdecode(file_bytes, cv2.IMREAD_UNCHANGED)

    bbs = pfs.get_image_bbs(cv2_image)
    faces = pfs.fp.extract_faces(cv2_image, bbs)
    face_vecs = pfs.pkfn.vectorize(faces)
    names = [get_identity(vec, pfs.reference_table) for vec in face_vecs]

    cv2_image_result = pfs.get_image_with_bbs(cv2_image)
    cv2_image_string = cv2.imencode('.png', cv2_image_result)[1].tostring()
    #DBG print('length:', len(cv2_image_string))
    response = make_response(cv2_image_string)
    response.headers['Content-Type'] = 'image/png'
    # response.headers['Content-Disposition'] = 'attachment; filename=image_result.jpg'
    return response