diff --git a/custom_components/deepstack_object/image_processing.py b/custom_components/deepstack_object/image_processing.py index 4da55d2..1d60193 100644 --- a/custom_components/deepstack_object/image_processing.py +++ b/custom_components/deepstack_object/image_processing.py @@ -4,7 +4,7 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/image_processing.deepstack_object """ -from collections import namedtuple +from collections import namedtuple, Counter import datetime import io import logging @@ -278,6 +278,7 @@ def __init__( ) self._custom_model = custom_model self._confidence = confidence + self._summary = {} self._targets = targets for target in self._targets: if CONF_CONFIDENCE not in target.keys(): @@ -334,6 +335,7 @@ def process_image(self, image): self._state = None self._objects = [] # The parsed raw data self._targets_found = [] + self._summary = {} saved_image_path = None try: @@ -369,6 +371,11 @@ def process_image(self, image): if self._state > 0: self._last_detection = dt_util.now().strftime(DATETIME_FORMAT) + targets_found = [ + obj["name"] for obj in self._targets_found + ] # Just the list of target names, e.g. [car, car, person] + self._summary = dict(Counter(targets_found)) # e.g. {'car':2, 'person':1} + if self._save_file_folder: if self._state > 0 or self._always_save_latest_jpg: saved_image_path = self.save_image( @@ -411,6 +418,7 @@ def device_state_attributes(self) -> Dict: attr["targets_found"] = [ {obj["name"]: obj["confidence"]} for obj in self._targets_found ] + attr["summary"] = self._summary if self._last_detection: attr["last_target_detection"] = self._last_detection if self._custom_model: