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