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

Commit

Permalink
Update image_processing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
robmarkcole committed Jan 24, 2021
1 parent 6f650f8 commit b90da96
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion custom_components/deepstack_object/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b90da96

Please sign in to comment.