找到一个矩形的左上,右上,右下,左下 四点

def FUN_order_points(pts):
# 一共4个坐标点
rect = np.zeros((4, 2), dtype = "float32")

# 按顺序找到对应坐标0123分别是 左上,右上,右下,左下
# 计算左上,右下
s = pts.sum(axis = 1) # 求 sum=x+y, 最小的是左上,最大的是右下
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]

# 计算右上和左下
diff = np.diff(pts, axis = 1) # 求diff=y-x, 最小的是右上,最大的是左下
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]

return rect

相关文章:

  • 2021-11-29
  • 2022-01-13
  • 2021-11-26
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-17
  • 2021-10-24
  • 2021-06-06
  • 2022-12-23
  • 2021-11-29
相关资源
相似解决方案