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

Commit

Permalink
Filter events by confidence
Browse files Browse the repository at this point in the history
Events are only fired for detections above the configured confidence threshold, to prevent many events for low confidence detections
  • Loading branch information
robmarkcole committed Aug 26, 2019
1 parent 0820fe8 commit 42a9cd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Configuration variables:
</p>

#### Event `image_processing.object_detected`
An event `image_processing.object_detected` is fired for each object detected. An example use case for this is incrementing a [counter](https://www.home-assistant.io/components/counter/) when a person is detected. The `image_processing.object_detected` event payload includes:
An event `image_processing.object_detected` is fired for each object detected above the configured `confidence` threshold. An example use case for this is incrementing a [counter](https://www.home-assistant.io/components/counter/) when a person is detected. The `image_processing.object_detected` event payload includes:

- `classifier` : the classifier (i.e. `deepstack_object`)
- `entity_id` : the entity id responsible for the event
Expand Down
23 changes: 12 additions & 11 deletions custom_components/deepstack_object/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def process_image(self, image):
get_confidences_above_threshold(
self._targets_confidences, self._confidence))
self._predictions = get_objects_summary(predictions_json)
self.fire_prediction_events(predictions_json)
self.fire_prediction_events(predictions_json, self._confidence)
if hasattr(self, "_save_file_folder") and self._state > 0:
self.save_image(
image, predictions_json, self._target, self._save_file_folder)
Expand Down Expand Up @@ -194,18 +194,19 @@ def save_image(self, image, predictions_json, target, directory):
except Exception as exc:
_LOGGER.error("Error saving bounding box image : %s", exc)

def fire_prediction_events(self, predictions_json):
"""Fire events based on predictions"""
def fire_prediction_events(self, predictions_json, confidence):
"""Fire events based on predictions if above confidence threshold."""

for prediction in predictions_json:
self.hass.bus.fire(
EVENT_OBJECT_DETECTED, {
'classifier': CLASSIFIER,
ATTR_ENTITY_ID: self.entity_id,
OBJECT: prediction['label'],
ATTR_CONFIDENCE: format_confidence(
prediction['confidence'])
})
if format_confidence(prediction['confidence']) > confidence:
self.hass.bus.fire(
EVENT_OBJECT_DETECTED, {
'classifier': CLASSIFIER,
ATTR_ENTITY_ID: self.entity_id,
OBJECT: prediction['label'],
ATTR_CONFIDENCE: format_confidence(
prediction['confidence'])
})

def fire_saved_file_event(self, save_path):
"""Fire event when saving a file"""
Expand Down

0 comments on commit 42a9cd1

Please sign in to comment.