-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions_characters.py
68 lines (48 loc) · 2.17 KB
/
functions_characters.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
import numpy as np
import cv2
def fix_i_j(rect, max_line_height, max_w):
# ========== correct dots commas
j = 0
i_dot_list = []
for i in rect:
x = i[0]
y = i[1]
w = i[2]
h = i[3]
#if the dot of i is the last element in the rect, the [j+1] index will not work. so we put [j-1] separately here
if (j is len(rect)-1 and (h < max_line_height/3)):
if( (h < max_line_height/3) and (abs(rect[j-1][0]+rect[j-1][2] - (x+w)) < max_w/3.5) ):
#correct i
#rect[j-1][3] = rect[j-1][3] + (rect[j-1][1] - y)
rect[j-1] = (rect[j-1][0], rect[j-1][1], rect[j-1][2], rect[j-1][3] + (rect[j-1][1] - y))
#rect[j-1][1] = y
rect[j-1] = (rect[j-1][0], y, rect[j-1][2], rect[j-1][3])
i_dot_list.append(j)
elif (h < max_line_height/2.4 and y > (rect[j-1][1] + rect[j-1][3]/3)):
#rect[j][1] = rect[j][1] - (max_line_height/2)
rect[j] = [x,y-(max_line_height/2),w,h+(max_line_height/2)]
#if the dot of i is not the last element in the rect
else:
if( (h < max_line_height/3) and (abs(rect[j+1][0]+rect[j+1][2] - (x+w)) < max_w/3.5)):
#correct i
#rect[j+1][3] = rect[j+1][3] + (rect[j+1][1] - y)
rect[j+1] = (rect[j+1][0], rect[j+1][1], rect[j+1][2], rect[j+1][3] + (rect[j+1][1] - y))
#rect[j+1][1] = y
rect[j+1] = (rect[j+1][0], y, rect[j+1][2], rect[j+1][3])
i_dot_list.append(j)
elif( (h < max_line_height/3) and (abs(rect[j-1][0]+rect[j-1][2] - (x+w)) < max_w/3.5) ):
#correct i
#rect[j-1][3] = rect[j-1][3] + (rect[j-1][1] - y)
rect[j-1] = (rect[j-1][0], rect[j-1][1], rect[j-1][2], rect[j-1][3] + (rect[j-1][1] - y))
#rect[j-1][1] = y
rect[j-1] = (rect[j-1][0], y, rect[j-1][2], rect[j-1][3])
i_dot_list.append(j)
elif (h < max_line_height/2.4 and y > (rect[j-1][1] + rect[j-1][3]/3)):
#rect[j][1] = rect[j][1] - (max_line_height/2)
rect[j] = [x,y-(max_line_height/2),w,h+(max_line_height/2)]
j = j + 1
# ===== end of fixing dots in i and j
#delete the dots from rect array which belongs to i and j
rect = np.delete(rect, i_dot_list, axis=0)
# =======================
return rect