From c37590ef3a6ed14744e2bbce2d493b3b8fb27675 Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Mon, 10 Apr 2023 19:17:53 +0200 Subject: [PATCH] add `area` and `box_area` to `Detections` object --- supervision/detection/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index e9e5e689..12a0e338 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -333,6 +333,20 @@ class Detections: @property def area(self) -> np.ndarray: + """ + Calculate the area of each detection in the set of object detections. If masks field is defined property + returns are of each mask. If only box is given property return area of each box. + + Returns: + np.ndarray: An array of floats containing the area of each detection in the format of `(area_1, area_2, ..., area_n)`, where n is the number of detections. + """ + if self.mask is not None: + return np.ndarray([np.sum(mask) for mask in self.mask]) + else: + return self.box_area + + @property + def box_area(self) -> np.ndarray: """ Calculate the area of each bounding box in the set of object detections.