diff --git a/ppocr/data/imaug/label_ops.py b/ppocr/data/imaug/label_ops.py index 36017a823ecd946be111d760ea65fd0a5451c34a..c20eef2c8c4481d46fae3f9006946b7a1b5c6bda 100644 --- a/ppocr/data/imaug/label_ops.py +++ b/ppocr/data/imaug/label_ops.py @@ -70,22 +70,15 @@ class DetLabelEncode(object): return data def order_points_clockwise(self, pts): - """ - refer to :https://github.com/PyImageSearch/imutils/blob/9f740a53bcc2ed7eba2558afed8b4c17fd8a1d4c/imutils/perspective.py#L9 - """ - # sort the points based on their x-coordinates - xSorted = pts[np.argsort(pts[:, 0]), :] - - leftMost = xSorted[:2, :] - rightMost = xSorted[2:, :] - - leftMost = leftMost[np.argsort(leftMost[:, 1]), :] - (tl, bl) = leftMost - - D = dist.cdist(tl[np.newaxis], rightMost, "euclidean")[0] - (br, tr) = rightMost[np.argsort(D)[::-1], :] - - return np.array([tl, tr, br, bl], dtype="float32") + rect = np.zeros((4, 2), dtype="float32") + s = pts.sum(axis=1) + rect[0] = pts[np.argmin(s)] + rect[2] = pts[np.argmax(s)] + tmp = np.delete(pts, (np.argmin(s), np.argmax(s)), axis=0) + diff = np.diff(np.array(tmp), axis=1) + rect[1] = tmp[np.argmin(diff)] + rect[3] = tmp[np.argmax(diff)] + return rect def expand_points_num(self, boxes): max_points_num = 0 diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 73387aef597716809c02657404456660734c4c7b..cf495c59c25cfe24ed0987b56cbe810579f1d542 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -151,22 +151,15 @@ class TextDetector(object): logger=logger) def order_points_clockwise(self, pts): - """ - refer to :https://github.com/PyImageSearch/imutils/blob/9f740a53bcc2ed7eba2558afed8b4c17fd8a1d4c/imutils/perspective.py#L9 - """ - # sort the points based on their x-coordinates - xSorted = pts[np.argsort(pts[:, 0]), :] - - leftMost = xSorted[:2, :] - rightMost = xSorted[2:, :] - - leftMost = leftMost[np.argsort(leftMost[:, 1]), :] - (tl, bl) = leftMost - - D = dist.cdist(tl[np.newaxis], rightMost, "euclidean")[0] - (br, tr) = rightMost[np.argsort(D)[::-1], :] - - return np.array([tl, tr, br, bl], dtype="float32") + rect = np.zeros((4, 2), dtype="float32") + s = pts.sum(axis=1) + rect[0] = pts[np.argmin(s)] + rect[2] = pts[np.argmax(s)] + tmp = np.delete(pts, (np.argmin(s), np.argmax(s)), axis=0) + diff = np.diff(np.array(tmp), axis=1) + rect[1] = tmp[np.argmin(diff)] + rect[3] = tmp[np.argmax(diff)] + return rect def clip_det_res(self, points, img_height, img_width): for pno in range(points.shape[0]):