Skip to content

Commit 6fed221

Browse files
committed
fixed a sort bug
1 parent 18bc144 commit 6fed221

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

main.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,27 @@ def __update_database(self):
7979
break
8080

8181
def __distance(self, p1, p2):
82-
return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) ** 0.5
82+
return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5
8383

8484
def __closest_pair(self, X, Y):
8585
if len(X) <= 3:
86-
return min([self.__distance(X[i], X[j]) for i in range(len(X)) for j in range(i+1, len(X))])
86+
return min([self.__distance(X[i], X[j]) for i in range(len(X)) for j in range(i + 1, len(X))])
8787

88-
mid = len(X)//2
88+
mid = len(X) // 2
8989
XL, XR = X[:mid], X[mid:]
9090
YL, YR = [p for p in Y if p in XL], [p for p in Y if p in XR]
9191

9292
d = min(self.__closest_pair(XL, YL), self.__closest_pair(XR, YR))
9393

9494
line = (X[mid][0] + X[mid-1][0]) / 2
95-
YS = [p for p in Y if abs(p[0]-line) < d]
95+
YS = [p for p in Y if abs(p[0] - line) < d]
9696

9797
return min(d, self.__closest_split_pair(YS, d))
9898

9999
def __closest_split_pair(self, Y, d):
100100
n = len(Y)
101-
for i in range(n-1):
102-
for j in range(i+1, min(i+8, n)):
101+
for i in range(n - 1):
102+
for j in range(i + 1, min(i + 8, n)):
103103
if self.__distance(Y[i], Y[j]) < d:
104104
d = self.__distance(Y[i], Y[j])
105105
return d
@@ -209,9 +209,6 @@ def recognize(self, image):
209209
print(i != j, len(eocr_result[i][0]) == 4, len(eocr_result[j][0]) == 4, disout)
210210
print("------------------------------C-")
211211

212-
pocr_result = [sorted(pocr_result[0], key=lambda x: len(x[1][0]), reverse=True)]
213-
eocr_result = sorted(eocr_result, key=lambda x: len(x[1]), reverse=True)
214-
215212
if self.debug:
216213
print(pocr_result)
217214
print(eocr_result)
@@ -230,7 +227,7 @@ def recognize(self, image):
230227
)
231228
ocr_filter.append(e[1])
232229

233-
ocr_result = sorted(ocr_result, key=lambda x:len(x[1]), reverse=True)
230+
ocr_result = sorted(ocr_result, key=lambda x:len(x[1]), reverse=True)
234231

235232
# Read database
236233
for i in ocr_result:

0 commit comments

Comments
 (0)