Skip to content
This repository was archived by the owner on Mar 19, 2023. It is now read-only.

Commit db30558

Browse files
authored
Merge pull request #206 from robmarkcole/add-summary-back
Add summary back
2 parents 6f650f8 + b90da96 commit db30558

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

custom_components/deepstack_object/image_processing.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
For more details about this platform, please refer to the documentation at
55
https://home-assistant.io/components/image_processing.deepstack_object
66
"""
7-
from collections import namedtuple
7+
from collections import namedtuple, Counter
88
import datetime
99
import io
1010
import logging
@@ -278,6 +278,7 @@ def __init__(
278278
)
279279
self._custom_model = custom_model
280280
self._confidence = confidence
281+
self._summary = {}
281282
self._targets = targets
282283
for target in self._targets:
283284
if CONF_CONFIDENCE not in target.keys():
@@ -334,6 +335,7 @@ def process_image(self, image):
334335
self._state = None
335336
self._objects = [] # The parsed raw data
336337
self._targets_found = []
338+
self._summary = {}
337339
saved_image_path = None
338340

339341
try:
@@ -369,6 +371,11 @@ def process_image(self, image):
369371
if self._state > 0:
370372
self._last_detection = dt_util.now().strftime(DATETIME_FORMAT)
371373

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+
372379
if self._save_file_folder:
373380
if self._state > 0 or self._always_save_latest_jpg:
374381
saved_image_path = self.save_image(
@@ -411,6 +418,7 @@ def device_state_attributes(self) -> Dict:
411418
attr["targets_found"] = [
412419
{obj["name"]: obj["confidence"]} for obj in self._targets_found
413420
]
421+
attr["summary"] = self._summary
414422
if self._last_detection:
415423
attr["last_target_detection"] = self._last_detection
416424
if self._custom_model:

0 commit comments

Comments
 (0)