faceplugin's picture
initial commit
901e379
raw
history blame
No virus
2.93 kB
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