From 990c6f54e1f2be4bcf1aedf89d5b163575f5554c Mon Sep 17 00:00:00 2001 From: Robin Cole Date: Thu, 14 Jan 2021 08:51:55 +0000 Subject: [PATCH 1/2] Update image_processing.py --- .../deepstack_object/image_processing.py | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/custom_components/deepstack_object/image_processing.py b/custom_components/deepstack_object/image_processing.py index 3b3d63e..f1865f0 100644 --- a/custom_components/deepstack_object/image_processing.py +++ b/custom_components/deepstack_object/image_processing.py @@ -270,7 +270,7 @@ def __init__( self._targets = targets for target in self._targets: if CONF_CONFIDENCE not in target.keys(): - target[CONF_CONFIDENCE] = self._confidence + target.update({CONF_CONFIDENCE: self._confidence}) self._targets_names = [ target[CONF_TARGET] for target in targets ] # can be a name or a type @@ -319,19 +319,24 @@ def process_image(self, image): self._targets_found = [] for obj in self._objects: - if obj["name"] or obj["object_type"] in self._targets_names: - ## Then check if the type has a configured confidence, if yes assign - ## Then if a confidence for a named object, this takes precedence over type confidence - confidence = self._confidence - for target in self._targets: - if target[CONF_TARGET] == obj["object_type"]: - confidence = target[CONF_CONFIDENCE] - for target in self._targets: - if target[CONF_TARGET] == obj["name"]: - confidence = target[CONF_CONFIDENCE] - if obj["confidence"] > confidence: - if object_in_roi(self._roi_dict, obj["centroid"]): - self._targets_found.append(obj) + if not ( + (obj["name"] in self._targets_names) + or (obj["object_type"] in self._targets_names) + ): + continue + ## Then check if the type has a configured confidence, if yes assign + ## Then if a confidence for a named object, this takes precedence over type confidence + confidence = None + for target in self._targets: + if obj["object_type"] == target[CONF_TARGET]: + confidence = target[CONF_CONFIDENCE] + for target in self._targets: + if obj["name"] == target[CONF_TARGET]: + confidence = target[CONF_CONFIDENCE] + if obj["confidence"] > confidence: + if not object_in_roi(self._roi_dict, obj["centroid"]): + continue + self._targets_found.append(obj) self._state = len(self._targets_found) if self._state > 0: @@ -375,6 +380,7 @@ def device_state_attributes(self) -> Dict: """Return device specific state attributes.""" attr = {} attr["targets"] = self._targets + attr["targets_names"] = self._targets_names attr["targets_found"] = [ {obj["name"]: obj["confidence"]} for obj in self._targets_found ] From fbb5f6522bd78f04a7fa879ff5dbea2ea61d32b5 Mon Sep 17 00:00:00 2001 From: Robin Cole Date: Thu, 14 Jan 2021 08:55:40 +0000 Subject: [PATCH 2/2] remove target names --- custom_components/deepstack_object/image_processing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/custom_components/deepstack_object/image_processing.py b/custom_components/deepstack_object/image_processing.py index f1865f0..2c9c79a 100644 --- a/custom_components/deepstack_object/image_processing.py +++ b/custom_components/deepstack_object/image_processing.py @@ -380,7 +380,6 @@ def device_state_attributes(self) -> Dict: """Return device specific state attributes.""" attr = {} attr["targets"] = self._targets - attr["targets_names"] = self._targets_names attr["targets_found"] = [ {obj["name"]: obj["confidence"]} for obj in self._targets_found ]