MCPcopy Create free account
hub / github.com/PyImageSearch/imutils / order_points

Function order_points

imutils/perspective.py:9–34  ·  view source on GitHub ↗
(pts)

Source from the content-addressed store, hash-verified

7import cv2
8
9def 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
36def four_point_transform(image, pts):
37 # obtain a consistent order of the points and unpack them

Callers 1

four_point_transformFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…