Meta Byte Track
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

detection.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # vim: expandtab:ts=4:sw=4
  2. import numpy as np
  3. class Detection(object):
  4. """
  5. This class represents a bounding box detection in a single image.
  6. Parameters
  7. ----------
  8. tlwh : array_like
  9. Bounding box in format `(x, y, w, h)`.
  10. confidence : float
  11. Detector confidence score.
  12. feature : array_like
  13. A feature vector that describes the object contained in this image.
  14. Attributes
  15. ----------
  16. tlwh : ndarray
  17. Bounding box in format `(top left x, top left y, width, height)`.
  18. confidence : ndarray
  19. Detector confidence score.
  20. feature : ndarray | NoneType
  21. A feature vector that describes the object contained in this image.
  22. """
  23. def __init__(self, tlwh, confidence, feature):
  24. self.tlwh = np.asarray(tlwh, dtype=np.float)
  25. self.confidence = float(confidence)
  26. self.feature = np.asarray(feature, dtype=np.float32)
  27. def to_tlbr(self):
  28. """Convert bounding box to format `(min x, min y, max x, max y)`, i.e.,
  29. `(top left, bottom right)`.
  30. """
  31. ret = self.tlwh.copy()
  32. ret[2:] += ret[:2]
  33. return ret
  34. def to_xyah(self):
  35. """Convert bounding box to format `(center x, center y, aspect ratio,
  36. height)`, where the aspect ratio is `width / height`.
  37. """
  38. ret = self.tlwh.copy()
  39. ret[:2] += ret[2:] / 2
  40. ret[2] /= ret[3]
  41. return ret