mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2025-06-03 21:53:39 +08:00
fix order_points_clockwise
This commit is contained in:
parent
edd0601582
commit
fabfaaba6a
@ -138,29 +138,15 @@ class TextDetector(object):
|
|||||||
logger=logger)
|
logger=logger)
|
||||||
|
|
||||||
def order_points_clockwise(self, pts):
|
def order_points_clockwise(self, pts):
|
||||||
"""
|
rect = np.zeros((4, 2), dtype="float32")
|
||||||
reference from: https://github.com/jrosebr1/imutils/blob/master/imutils/perspective.py
|
s = pts.sum(axis=1)
|
||||||
# sort the points based on their x-coordinates
|
rect[0] = pts[np.argmin(s)]
|
||||||
"""
|
rect[2] = pts[np.argmax(s)]
|
||||||
xSorted = pts[np.argsort(pts[:, 0]), :]
|
diff = np.diff(pts, axis=1)
|
||||||
|
rect[1] = pts[np.argmin(diff)]
|
||||||
# grab the left-most and right-most points from the sorted
|
rect[3] = pts[np.argmax(diff)]
|
||||||
# x-roodinate points
|
|
||||||
leftMost = xSorted[:2, :]
|
|
||||||
rightMost = xSorted[2:, :]
|
|
||||||
|
|
||||||
# now, sort the left-most coordinates according to their
|
|
||||||
# y-coordinates so we can grab the top-left and bottom-left
|
|
||||||
# points, respectively
|
|
||||||
leftMost = leftMost[np.argsort(leftMost[:, 1]), :]
|
|
||||||
(tl, bl) = leftMost
|
|
||||||
|
|
||||||
rightMost = rightMost[np.argsort(rightMost[:, 1]), :]
|
|
||||||
(tr, br) = rightMost
|
|
||||||
|
|
||||||
rect = np.array([tl, tr, br, bl], dtype="float32")
|
|
||||||
return rect
|
return rect
|
||||||
|
|
||||||
def clip_det_res(self, points, img_height, img_width):
|
def clip_det_res(self, points, img_height, img_width):
|
||||||
for pno in range(points.shape[0]):
|
for pno in range(points.shape[0]):
|
||||||
points[pno, 0] = int(min(max(points[pno, 0], 0), img_width - 1))
|
points[pno, 0] = int(min(max(points[pno, 0], 0), img_width - 1))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user