pts_letterbox.py 613 B

12345678910111213141516171819
  1. __all__ = ['letterbox_2d_points', 'unletterbox_2d_points']
  2. def letterbox_2d_points(points, scale=1.0, pad_left=0, pad_top=0, copy=True):
  3. if copy:
  4. points = points.copy()
  5. points[..., 0::2] = points[..., 0::2] * scale + pad_left
  6. points[..., 1::2] = points[..., 1::2] * scale + pad_top
  7. return points
  8. def unletterbox_2d_points(points, scale=1.0, pad_left=0, pad_top=0, copy=True):
  9. if copy:
  10. points = points.copy()
  11. points[..., 0::2] = (points[..., 0::2] - pad_left) / scale
  12. points[..., 1::2] = (points[..., 1::2] - pad_top) / scale
  13. return points