-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
82 lines (53 loc) · 1.67 KB
/
app.py
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
from flask import Flask, render_template, Response, redirect
import cv2, boto3
from VideoCamera import VideoCamera
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
videoStream = VideoCamera()
curr_detection_mode = 0
# Defaults to faces
@app.route('/')
def reroute():
return redirect("/main")
@app.route("/main")
def mainPage():
return render_template("Frontend/home.html")
@app.route("/camera")
def cameraPage():
return render_template("Frontend/camera.html")
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/png\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/video_feed')
# Sent directly to video camera / webcam element
def video_feed():
return Response(gen(videoStream), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/detect_faces')
def detect_faces():
global curr_detection_mode
curr_detection_mode = 0
return render_template("Frontend/output.html")
@app.route('/detect_labels')
def detect_labels():
global curr_detection_mode
curr_detection_mode = 1
return render_template("Frontend/output.html")
@app.route('/detect_text')
def detect_text():
global curr_detection_mode
curr_detection_mode = 2
return render_template("Frontend/output.html")
@app.route('/source_image')
# Send directly to the image element
def source_image():
global curr_detection_mode
if(curr_detection_mode == 0):
picture = videoStream.face_detections()
elif(curr_detection_mode == 1):
picture = videoStream.label_detections()
else:
picture = videoStream.text_detections()
return picture