Untitled

mail@pastecode.io avatar
unknown
python
a year ago
2.5 kB
4
Indexable
Never
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
import extractData
import compareFace as cp

app = Flask(__name__)
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

@app.route('/extract/front', methods=['POST'])
@cross_origin(origins='*')
def detection_info():
    data = request.get_json()
    idCardImgUrl = data["imageUrl"]
    email = data["email"]
    informationCard = extractData.getInfomationIdCard(idCardImgUrl, email)

    if informationCard == False:
        return jsonify({
            'message': 'URL request failed with status code 400',
            'success': False
        })

    if informationCard == "":
        response = jsonify({
            'message': 'Error detection ID Card. Please upload ID card again!',
            'success': False
        })
        response.status_code = 400
        return response
    else:
        infoIdCard = informationCard.split('|')
        response = jsonify({
            'data': {
                "CCCD": infoIdCard[0],
                "CMND": infoIdCard[1],
                "Name": infoIdCard[2],
                "Birthday": infoIdCard[3],
                "Gender": infoIdCard[4],
                "PermanentResidenceAddress": infoIdCard[5],
                "CardIssueDate": infoIdCard[6],
                "QrCodeImgUrl": "https://agm-match.sgp1.digitaloceanspaces.com/AGM/"+ email +"/qrcode.jpg",
                "FaceImgUrl": "https://agm-match.sgp1.digitaloceanspaces.com/AGM/"+ email +"/face.jpg",
                "IDCardUrl": "https://agm-match.sgp1.digitaloceanspaces.com/AGM/"+ email +"/idCard.jpg"
            },
            'success': True
        })
        response.status_code = 200
        return response

@app.route('/compare/face', methods=['POST','GET'])
@cross_origin(origins='*')
def detection_face():
    data = request.get_json()
    faceIdCardImage = data["imageFaceIdCard"]
    selfieImage = data["selfieImage"]

    compareFace = cp.compareFace(faceIdCardImage, selfieImage)

    if (float(compareFace) >= 40):
        return jsonify({
            "data": {
                "numberPercent": compareFace,
                "match": True,
            },
            "success": True
        })
    else:
        return jsonify({
            "data": {
                "numberPercent": compareFace,
                "match": False,
            },
            "success": False
        })

if __name__ == '__main__':
    app.run(host='0.0.0.0', port='4000')