-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·65 lines (50 loc) · 1.5 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
import os
import sys
import cv2
from flask import Flask, send_from_directory
from google.cloud import vision
from scripts.scene_detection import *
from scripts.text_to_speech import *
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="credentials.json"
app = Flask(__name__)
client = vision.ImageAnnotatorClient()
@app.route("/")
def index():
return send_from_directory("static", "index.html")
@app.route("/reset")
def reset():
python = sys.executable
os.execl(python, python, *sys.argv)
@app.route("/detect-text")
def route_detect_text():
content = capture_frame()
cv2.imwrite('image.png', content)
image = cv2.imread('image.png')
_, encoded_image = cv2.imencode('.png', image)
content = encoded_image.tobytes()
image = vision.types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
os.remove('image.png')
print('Texts:')
# for text in texts:
# print('\n"{}"'.format(text.description))
try:
sent = '\n{}'.format(texts[0].description)
speech(sent)
print(sent)
except:
pass
return ""
@app.route("/detect-scene")
def route_detect_scene():
scene,obj = scene_detect()
speech(scene)
if obj != None:
speech(obj)
return "scene: " + scene +" obj: " + str(obj)
@app.route("/caption")
def route_caption():
return ""
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)