|
4 | 4 | For more details about this platform, please refer to the documentation at |
5 | 5 | https://home-assistant.io/components/image_processing.deepstack_object |
6 | 6 | """ |
7 | | -from collections import namedtuple |
| 7 | +from collections import namedtuple, Counter |
8 | 8 | import datetime |
9 | 9 | import io |
10 | 10 | import logging |
@@ -278,6 +278,7 @@ def __init__( |
278 | 278 | ) |
279 | 279 | self._custom_model = custom_model |
280 | 280 | self._confidence = confidence |
| 281 | + self._summary = {} |
281 | 282 | self._targets = targets |
282 | 283 | for target in self._targets: |
283 | 284 | if CONF_CONFIDENCE not in target.keys(): |
@@ -334,6 +335,7 @@ def process_image(self, image): |
334 | 335 | self._state = None |
335 | 336 | self._objects = [] # The parsed raw data |
336 | 337 | self._targets_found = [] |
| 338 | + self._summary = {} |
337 | 339 | saved_image_path = None |
338 | 340 |
|
339 | 341 | try: |
@@ -369,6 +371,11 @@ def process_image(self, image): |
369 | 371 | if self._state > 0: |
370 | 372 | self._last_detection = dt_util.now().strftime(DATETIME_FORMAT) |
371 | 373 |
|
| 374 | + targets_found = [ |
| 375 | + obj["name"] for obj in self._targets_found |
| 376 | + ] # Just the list of target names, e.g. [car, car, person] |
| 377 | + self._summary = dict(Counter(targets_found)) # e.g. {'car':2, 'person':1} |
| 378 | + |
372 | 379 | if self._save_file_folder: |
373 | 380 | if self._state > 0 or self._always_save_latest_jpg: |
374 | 381 | saved_image_path = self.save_image( |
@@ -411,6 +418,7 @@ def device_state_attributes(self) -> Dict: |
411 | 418 | attr["targets_found"] = [ |
412 | 419 | {obj["name"]: obj["confidence"]} for obj in self._targets_found |
413 | 420 | ] |
| 421 | + attr["summary"] = self._summary |
414 | 422 | if self._last_detection: |
415 | 423 | attr["last_target_detection"] = self._last_detection |
416 | 424 | if self._custom_model: |
|
0 commit comments