def face_match():
    if request.method == 'POST':
        img1 = request.values.get("img1")
        img2 = request.values.get("img2")

        if img1 and img2 and allowed_file(img1) and allowed_file(img2):
            file_path1 = os.path.join(os.getcwd(), img1)
            file_path2 = os.path.join(os.getcwd(), img2)
            return detect_faces_in_image(file_path1, file_path2,
                                         request.values.get("tolerance"))

    return '''
Beispiel #2
0
def pp_mrz():
    if request.method == 'POST':
        img1 = request.values.get("img1")

        if img1 and allowed_file(img1):
            file_path1 = os.path.join(os.getcwd(), img1)
            return pp_mrz_(file_path1)

    return '''
Beispiel #3
0
def face_locat():
    if request.method == 'POST':
        img1 = request.values.get("img1")
        #print img1
        if img1 and allowed_file(img1):
            file_path = os.path.join(os.getcwd(), img1)
            result = face_recognition.face_locations(
                face_recognition.load_image_file(file_path))
            #print(jsonify(result))
            return jsonify(result)

    return '''
def face_upload():
    if request.method == 'POST':
        if 'img1' not in request.files:
            return redirect(request.url)

        img1 = request.files['img1']

        if img1.filename == '':
            return redirect(request.url)

        if img1 and allowed_file(img1.filename):
            dt = datetime.now()  #创建一个datetime类对象
            dt.strftime('%Y-%m-%d %H:%M:%S %f')
            path = os.path.join('upload', dt.strftime('%Y%m'))
            if not os.path.exists(os.path.join(os.getcwd(), path)):
                os.makedirs(path)
            filename = dt.strftime('%Y%m%d%H%M%S%f_.') + file_ext(
                img1.filename)
            file_path = os.path.join(os.getcwd(), path, filename)
            img1.save(file_path)
            result = {'filePath': os.path.join(path, filename)}
            return jsonify(result)

    return '''
Beispiel #5
0
def face_landmarks_alive():
    if request.method == 'POST':
        img1 = request.values.get("img1")

        if img1 and allowed_file(img1):
            result = {
                #landmarks : {},
                'openMouth': False,
                'closeEyes': False,
                'lookLeft': False,
                'lookRight': False
            }
            file_path = os.path.join(os.getcwd(), img1)
            landmarks = face_recognition.face_landmarks(
                face_recognition.load_image_file(file_path))
            #print(jsonify(landmarks))
            if len(landmarks) > 0:
                result['landmarks'] = landmarks[0]
                #取到边框
                min_x = min_y = 10000
                max_x = max_y = 0
                for k in landmarks[0]:
                    for p in landmarks[0][k]:
                        min_x = min(min_x, p[0])
                        min_y = min(min_y, p[1])
                        max_x = max(max_x, p[0])
                        max_y = max(max_y, p[1])
                #判断张嘴
                lip_top = landmarks[0]["top_lip"][9]
                lip_bottom = landmarks[0]["bottom_lip"][9]
                lip = abs((lip_top[1] - lip_bottom[1]) * 1.0 / (max_y - min_y))
                lip_n = 0.06
                if request.values.get("openMouth"):
                    lip_n = float(request.values.get("openMouth"))
                if lip > lip_n:
                    result['openMouth'] = True
                #print lip_top
                #print lip_bottom
                #print max_y
                #print min_y
                #print lip
                #print('lip=%.f' %(lip))
                #闭眼判断
                eye_right_top = landmarks[0]["left_eye"][1]
                eye_right_bottom = landmarks[0]["left_eye"][5]
                eye_left_top = landmarks[0]["right_eye"][1]
                eye_left_bottom = landmarks[0]["right_eye"][5]
                eye_right = abs((eye_right_top[1] - eye_right_bottom[1]) *
                                1.0 / (max_y - min_y))
                eye_left = abs((eye_left_top[1] - eye_left_bottom[1]) * 1.0 /
                               (max_y - min_y))
                eye_n = 0.04
                if request.values.get("closeEyes"):
                    eye_n = float(request.values.get("closeEyes"))
                if eye_right < eye_n and eye_left < eye_n:
                    result['closeEyes'] = True
                #print eye_right
                #print eye_left

                #左看右看
                right = landmarks[0]["chin"][0]
                left = landmarks[0]["chin"][16]

                le = abs((left[0] - eye_left_top[0]) * 1.0 / (max_x - min_x))
                ri = abs((right[0] - eye_right_top[0]) * 1.0 / (max_x - min_x))
                look_n = 0.2
                if request.values.get("lookLeftRight"):
                    look_n = float(request.values.get("lookLeftRight"))
                if le < look_n:
                    result['lookLeft'] = True
                if ri < look_n:
                    result['lookRight'] = True
                #print le
                #print ri

            return jsonify(result)

    return '''