-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoxFinder.py
45 lines (44 loc) · 1.55 KB
/
BoxFinder.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
#from Fedex import FedEx
import numpy as np
def group_lines(line_dict,xbias=5,ybias=25):
locs=list(line_dict.keys())
values=list(line_dict.values())
y=[i[1] for i in locs]
order=np.argsort(y)
values=np.array(values)[order]
locs=np.array(locs)[order]
boxLocs=[]
boxValues=[]
while(len(locs)!=0):
tmp_locs = []
indices=[]
start=-1
txt=[]
prev=[]
end=0
for i in range(len(locs)):
if start==-1:
txt.append(values[i])
tmp_locs.append(locs[i])
start=i
indices.append(i)
prev=locs[i]
else:
x_start=float(prev[0])
y_start=float(prev[3])
if float(locs[i][0]) > x_start - xbias and float(locs[i][0]) < x_start+xbias and float(locs[i][1]) < y_start+ybias:
txt.append(values[i])
tmp_locs.append(locs[i])
indices.append(i)
prev=locs[i]
else:
continue
"""print(tmp_locs[0][0],tmp_locs[0][1],tmp_locs[len(tmp_locs)-1][2],tmp_locs[len(tmp_locs)-1][3])
print(txt)"""
boxLocs.append((tmp_locs[0][0],tmp_locs[0][1],tmp_locs[len(tmp_locs)-1][2],tmp_locs[len(tmp_locs)-1][3]))
boxValues.append(u'\n'.join(txt))
tmp=[locs[j] for j in range(len(locs)) if j not in indices]
locs=tmp
tmp = [values[j] for j in range(len(values)) if j not in indices]
values=tmp
return boxLocs,boxValues