Graduate

Move verification server to flask

from flask import Flask, render_template, Response, request
from flask import Flask, render_template, Response, request, jsonify
import json
import cv2
import numpy as np
import time
......@@ -6,7 +7,6 @@ import datetime
import sys
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
num = 3
app = Flask(__name__)
@app.route('/')
......@@ -15,7 +15,11 @@ def index():
return render_template('index.html')
@app.route('/submit', methods=['POST'])
def submit():
image = request.args.get('image')
print(type(image))
@app.route('/verify', methods=['POST'])
def verify():
image = request.form['image']
data = request.form['data']
return jsonify(test)
#recv = verify_face(image)
#return recv
......
......@@ -6,8 +6,8 @@
<style>
#container {
margin: 0px auto;
width: 1280px;
height: 1280px;
width: 640px;
height: 480px;
border: 10px #333 solid;
}
#videoInput {
......@@ -19,6 +19,7 @@
</style>
<script type='text/javascript' src="{{url_for('static', filename='js/opencv.js')}}"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/utils.js')}}"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type='text/javascript'>
function load_cascade()
{
......@@ -86,14 +87,13 @@ function processVideo() {
cropped = src.roi(rect);
let tempCanvas = document.createElement("canvas");
cv.imshow(tempCanvas,cropped);
let b64encoded = tempCanvas.toDataURL('image/jpeg', 1.0);
var msg = {
action: "verify",
img: b64encoded,
date: Date.now()
};
let socket = new WebSocket("ws://13.124.104.70:3000");
socket.send(JSON.stringify(msg));
let b64encoded = tempCanvas.toDataURL("image/jpeg", 1.0);
$.ajax({
type: "POST",
url: "{{url_for('verify')}}",
dataType: "json",
data: {'image':b64encoded, 'data':'testestest'}
});
}
cv.imshow('canvasOutput', dst);
// schedule the next one.
......@@ -111,6 +111,7 @@ setTimeout(processVideo, 0);
<div id="container">
<video autoplay="true" id="videoInput" width=640 height=480 style="display: none;"></video>
<canvas id="canvasOutput" width=640 height=480></canvas>
<div id="hidden_container" style="display: none;"><div>
</div>
</body>
</html>
......
......@@ -4,3 +4,4 @@ opencv-python==4.1.1.26
websockets
cryptography
pymysql
flask
......
[client]
user=root
password=1234
host=localhost
user=admin
password=attendance
host=attendance-system.c4yvip5o6czh.ap-northeast-2.rds.amazonaws.com
database=attendance
charset=utf8
......