(pts)
| 7 | import cv2 |
| 8 | |
| 9 | def order_points(pts): |
| 10 | # sort the points based on their x-coordinates |
| 11 | xSorted = pts[np.argsort(pts[:, 0]), :] |
| 12 | |
| 13 | # grab the left-most and right-most points from the sorted |
| 14 | # x-roodinate points |
| 15 | leftMost = xSorted[:2, :] |
| 16 | rightMost = xSorted[2:, :] |
| 17 | |
| 18 | # now, sort the left-most coordinates according to their |
| 19 | # y-coordinates so we can grab the top-left and bottom-left |
| 20 | # points, respectively |
| 21 | leftMost = leftMost[np.argsort(leftMost[:, 1]), :] |
| 22 | (tl, bl) = leftMost |
| 23 | |
| 24 | # now that we have the top-left coordinate, use it as an |
| 25 | # anchor to calculate the Euclidean distance between the |
| 26 | # top-left and right-most points; by the Pythagorean |
| 27 | # theorem, the point with the largest distance will be |
| 28 | # our bottom-right point |
| 29 | D = dist.cdist(tl[np.newaxis], rightMost, "euclidean")[0] |
| 30 | (br, tr) = rightMost[np.argsort(D)[::-1], :] |
| 31 | |
| 32 | # return the coordinates in top-left, top-right, |
| 33 | # bottom-right, and bottom-left order |
| 34 | return np.array([tl, tr, br, bl], dtype="float32") |
| 35 | |
| 36 | def four_point_transform(image, pts): |
| 37 | # obtain a consistent order of the points and unpack them |
no outgoing calls
no test coverage detected
searching dependent graphs…