点按x坐标从小到大排序


: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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值