:param pts: [[243.,9.], [ 4.,15.], [245.,233.], [ 5.,15.]]
type:array :
return: """
# 基于x坐标进行排序
sorted_x = pts[np.argsort(pts[:, 0]), :]
# 最左边的两个点 leftmost = sorted_x[:2, :]
# 最右边的两个点 rightmost = sorted_x[2:, :]
if(leftmost[0, 1] != leftmost[1, 1]):
# 最左边两个点的y坐标不同时,按y坐标从小到大排序
leftmost = leftmost[np.argsort(leftmost[:, 1]), :] else:
# 最左边两个点的y坐标相同时,按x坐标从大到小排序
leftmost = leftmost[np.argsort(leftmost[:, 0])[::-1], :]
(tl, bl) = leftmost
if rightmost[0, 1] != rightmost[1, 1]:
# 最右边两个点的y坐标不同时,按y坐标从小到大排序
rightmost = rightmost[np.argsort(rightmost[:, 1]), :]
else:
# 最右边两个点的y坐标相同时,按x坐标从大到小排序
rightmost = rightmost[np.argsort(rightmost[:, 0])[::-1], :]
(tr, br) = rightmost
return np.array([tl, tr, br, bl], dtype="float32")
作者:懒癌重度患者drive
链接:https://www.jianshu.com/p/5f192e80e993
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。