-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhocr_ocr_result_word.py
41 lines (28 loc) · 1.06 KB
/
hocr_ocr_result_word.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
from dataclasses import dataclass
from PySide6 import QtCore
from hocr_data import HOCR_Data
@dataclass
class HOCR_OCRResultWord(HOCR_Data):
text = ''
confidence = 0
def split_title_data(self, word):
if word:
self.title_data = word['title']
super().split_title_data()
self.text = word.get_text()
data_lines = self.title_data.split('; ')
for data_line in data_lines:
tokens = data_line.split(' ')
if tokens[0] == 'x_wconf':
self.confidence = int(tokens[1])
def translate(self, distance: QtCore.QPoint):
'''Translate coordinates by a distance'''
self.bbox = self.bbox.translated(distance)
def write(self, file: QtCore.QDataStream):
file.writeQVariant(self.bbox)
file.writeString(self.text)
file.writeInt16(self.confidence)
def read(self, file: QtCore.QDataStream):
self.bbox = file.readQVariant()
self.text = file.readString()
self.confidence = file.readInt16()