Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def order_points(pts):
- #input format
- #pts = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
- #sort points by x
- tmp = sorted(pts, key=lambda point: point[0])
- #tmp[0] and tmp[1] is left point
- #determine, which is top, and which is bottom by y coordinate
- if tmp[0][1] > tmp[1][1]:
- tl = tmp[1]
- bl = tmp[0]
- else:
- tl = tmp[0]
- bl = tmp[1]
- #do it with right tmp[2] and tmp[3]
- if tmp[2][1] > tmp[3][1]:
- tr = tmp[3]
- br = tmp[2]
- else:
- tr = tmp[2]
- br = tmp[3]
- return np.array([tl,tr,br,bl])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement