File size: 2,933 Bytes
901e379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import cv2
import numpy as np
import base64
import face_manage.manage as db_manage
from flask import Flask, render_template, request, jsonify
from extract import GetImageInfo

app = Flask(__name__)

UPLOAD_FOLDER = os.path.basename('uploads')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


@app.route("/")
def start_page():
    print("Start")
    response = jsonify({"status": "Start"})
    response.status_code = 200
    response.headers["Content-Type"] = "application/json; charset=utf-8"
    return response


@app.route("/enroll")
def enroll():
    file = request.files['image']
    image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_UNCHANGED)

    db_manage.open_database(0)
    count, boxes, scores, landmarks, alignimgs, features = GetImageInfo(image, 5)

    for idx in range(0, count):
        db_manage.register_face('sample name', idx, boxes[idx], landmarks[idx], alignimgs[idx], features[idx])

    # db_manage.clear_database()

    response = jsonify({"status": "True"})
    response.status_code = 200
    response.headers["Content-Type"] = "application/json; charset=utf-8"
    return response


@app.route("/delete/all")
def delete_all():
    db_manage.open_database(0)
    db_manage.clear_database()

    response = jsonify({"status": "True"})
    response.status_code = 200
    response.headers["Content-Type"] = "application/json; charset=utf-8"
    return response


@app.route("/match11")
def match_1_1():
    file1 = request.files['image1']
    file2 = request.files['image2']

    image1 = cv2.imdecode(np.fromstring(file1.read(), np.uint8), cv2.IMREAD_UNCHANGED)
    image2 = cv2.imdecode(np.fromstring(file2.read(), np.uint8), cv2.IMREAD_UNCHANGED)

    count1, boxes1, scores1, landmarks1, alignimgs1, features1 = GetImageInfo(image1, 1)
    count2, boxes2, scores2, landmarks2, alignimgs2, features2 = GetImageInfo(image2, 1)

    if count1 != 0 and count2 != 0:
        sim = db_manage.get_similarity(features1[0], features2[0])
        if sim > db_manage.threshold:
            result = True
        else:
            result = False

    response = jsonify({"status": result})
    response.status_code = 200
    response.headers["Content-Type"] = "application/json; charset=utf-8"
    return response


@app.route("/match1n")
def match_1_n():
    file = request.files['image']
    image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_UNCHANGED)

    result, filename, sub_index = False, None, -1
    count, boxes, scores, landmarks, alignimgs, features = GetImageInfo(image, 1)

    for idx in range(count):
        id, fn, sub_id = db_manage.verify_face(features[idx])
        if id != -1:
            result, filename, sub_index = True, fn, id

    response = jsonify({"status": result, "filename": filename, "subIndex": sub_index})
    response.status_code = 200
    response.headers["Content-Type"] = "application/json; charset=utf-8"
    return response