Skip to content

Commit

Permalink
fixed a sort bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bigsk05 committed Jan 22, 2023
1 parent 18bc144 commit 6fed221
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,27 @@ def __update_database(self):
break

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

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

mid = len(X)//2
mid = len(X) // 2
XL, XR = X[:mid], X[mid:]
YL, YR = [p for p in Y if p in XL], [p for p in Y if p in XR]

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

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

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

def __closest_split_pair(self, Y, d):
n = len(Y)
for i in range(n-1):
for j in range(i+1, min(i+8, n)):
for i in range(n - 1):
for j in range(i + 1, min(i + 8, n)):
if self.__distance(Y[i], Y[j]) < d:
d = self.__distance(Y[i], Y[j])
return d
Expand Down Expand Up @@ -209,9 +209,6 @@ def recognize(self, image):
print(i != j, len(eocr_result[i][0]) == 4, len(eocr_result[j][0]) == 4, disout)
print("------------------------------C-")

pocr_result = [sorted(pocr_result[0], key=lambda x: len(x[1][0]), reverse=True)]
eocr_result = sorted(eocr_result, key=lambda x: len(x[1]), reverse=True)

if self.debug:
print(pocr_result)
print(eocr_result)
Expand All @@ -230,7 +227,7 @@ def recognize(self, image):
)
ocr_filter.append(e[1])

ocr_result = sorted(ocr_result, key=lambda x:len(x[1]), reverse=True)
ocr_result = sorted(ocr_result, key=lambda x:len(x[1]), reverse=True)

# Read database
for i in ocr_result:
Expand Down

0 comments on commit 6fed221

Please sign in to comment.