-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.py
88 lines (61 loc) · 2.33 KB
/
pipeline.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
83
84
85
86
87
88
import imgToText
import LingoVisionTTS
import LingoVisionTranslator
import textBoundsUI
import threading
import playAudio
import time
import firestore_stuff
from firebase_admin import firestore
currently_running = False
language = 'EN-US'
def on_snapshot(doc_snapshot, changes, read_time):
global language
for doc in doc_snapshot:
print(f'Received document snapshot: {doc.id}')
settings = doc_snapshot[0].to_dict()
language = settings['language']
print('Updated settings:', settings)
db = firestore.client()
db.collection(u'settings').document(u'setting').on_snapshot(on_snapshot)
def pipeline(frame, coordinate, set_current_frame):
def runner():
global currently_running
currently_running = True
set_current_frame(frame, coordinate)
playAudio.startSound()
print('received frame of size', len(frame), 'and coordinates:', coordinate)
# Extract the text at the target location
text, boxes, targeted_box = imgToText.detect_text_swagger(frame, coordinate)
print('Boxes:', boxes, 'Targetted Box:', targeted_box)
print('Original:', text)
with open('frame.jpg', 'wb') as file:
file.write(frame)
# Overlay boxes to show where OCR is being executed, along with the target frame
textBoundsUI.textBoundDebug('frame.jpg', boxes, targeted_box)
with open('screenshot.jpeg', 'rb') as file:
boxed_frame = file.read()
# Freezeframe that is used for analysis
set_current_frame(boxed_frame, coordinate)
if not text:
playAudio.errorSound()
time.sleep(0.5)
print('No text detected')
text = 'No text detected!'
translated, source_language = LingoVisionTranslator.translateText(text, language)
print('Translated:', translated)
# Update databse
firestore_stuff.add_translation(
start_lang=source_language,
end_lang=language,
source_text=text,
translated_text=translated,
source_img=boxed_frame
)
LingoVisionTTS.textToSpeech(translated, language)
currently_running = False
if not currently_running:
thread = threading.Thread(target=runner)
thread.start()
else:
print('Already running - skipping command')