-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreads.py
More file actions
66 lines (51 loc) · 2.39 KB
/
threads.py
File metadata and controls
66 lines (51 loc) · 2.39 KB
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
from PySide6 import QtCore
from PIL import Image
from process_recognition_image import RecognitionProcessingImage
from process_recognition_pdf import RecognitionProcessingPDF
from process_recognition_sound import RecognitionProcessingSound
class RecognitionThreadImage(QtCore.QThread):
finished_one_rec_signal = QtCore.Signal(str, Image.Image, list) # A signal for transmitting the results of each image
all_finished_signal = QtCore.Signal()
def __init__(self, image_paths):
super().__init__()
self.image_paths = image_paths
def run(self):
result_text = ""
all_errors = []
for path in self.image_paths:
image = RecognitionProcessingImage(path)
text, errors = image.recognize_text
result_text += text # Result text
all_errors = errors + all_errors
result_text += "\n----------Separator-----------\n"
picture_image = image.before_image
self.finished_one_rec_signal.emit(result_text, picture_image, errors) # Signal that the thread is finished
self.all_finished_signal.emit() # Signal that the thread is finished
class RecognitionThreadSound(QtCore.QThread):
finished_signal = QtCore.Signal(str, list)
def __init__(self, audio_paths):
super().__init__()
self.audio_paths = audio_paths # List of paths to audio files
def run(self):
result_text = ""
all_errors = []
for path in self.audio_paths:
text, errors = RecognitionProcessingSound(path).recognize_text
all_errors = errors + all_errors
result_text += text
result_text += "\n----------Separator-----------\n"
self.finished_signal.emit(result_text, all_errors) # Signal that the thread is finished
class RecognitionThreadPDF(QtCore.QThread):
finished_signal = QtCore.Signal(str, list)
def __init__(self, pdf_paths):
super().__init__()
self.pdf_paths = pdf_paths # List of paths to PDF files
def run(self):
result_text = ""
all_errors = []
for path in self.pdf_paths:
text, errors = RecognitionProcessingPDF(path).recognize
all_errors = errors + all_errors
result_text += text
result_text += "\n----------Separator-----------\n"
self.finished_signal.emit(result_text, all_errors) # Signal that the thread is finished