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

Commit

Permalink
Merge pull request #103 from robmarkcole/fix-102
Browse files Browse the repository at this point in the history
Fix 102
  • Loading branch information
robmarkcole authored Feb 13, 2020
2 parents 751d8f9 + 6963cb4 commit e9ce502
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 1,437 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ docker run -e VISION-DETECTION=True -e API-KEY="Mysecretkey" -v localstorage:/da
```

## Usage of this component
The `deepstack_object` component adds an `image_processing` entity where the state of the entity is the total number of `target` objects that are above a `confidence` threshold which has a default value of 80%. The time of the last detection of the `target` object is in the `last detection` attribute. The type and number of objects (of any confidence) is listed in the `summary` attributes. Optionally the processed image can be saved to disk. If `save_file_folder` is configured an image with filename of format `deepstack_object_{source name}_latest_{target}.jpg` is over-written on each new detection of the `target`. Optionally this image can also be saved with a timestamp in the filename, if `save_timestamped_file` is configred as `True`. An event `image_processing.object_detected` is fired for each object detected. If you are a power user with advanced needs such as zoning detections or you want to track multiple object types, you will need to use the `image_processing.object_detected` events.
The `deepstack_object` component adds an `image_processing` entity where the state of the entity is the total number of `target` objects that are above a `confidence` threshold which has a default value of 80%. The time of the last detection of the `target` object is in the `last detection` attribute. The type and number of objects (of any confidence) is listed in the `summary` attributes. Optionally the processed image can be saved to disk. If `save_file_folder` is configured an image with filename of format `deepstack_object_{source name}_latest_{target}.jpg` is over-written on each new detection of the `target`. Optionally this image can also be saved with a timestamp in the filename, if `save_timestamped_file` is configred as `True`. An event `deepstack.object_detected` is fired for each object detected. If you are a power user with advanced needs such as zoning detections or you want to track multiple object types, you will need to use the `deepstack.object_detected` events.

**Note** that by default the component will **not** automatically scan images, but requires you to call the `image_processing.scan` service e.g. using an automation triggered by motion. Alternativley, periodic scanning can be enabled by configuring a `scan_interval`. The use of `scan_interval` [is described here](https://www.home-assistant.io/components/image_processing/#scan_interval-and-optimising-resources).

Expand All @@ -50,6 +50,9 @@ image_processing:
# scan_interval: 30 # Optional, in seconds
save_file_folder: /config/snapshots/
save_timestamped_file: True
target:
- person
- car
source:
- entity_id: camera.local_file
name: deepstack_person_detector
Expand All @@ -75,13 +78,13 @@ Configuration variables:
<img src="https://github.com/robmarkcole/HASS-Deepstack-object/blob/master/docs/object_detail.png" width="350">
</p>

#### Event `image_processing.file_saved`
If `save_file_folder` is configured, an new image will be saved with bounding boxes of detected `target` objects, and the filename will include the time of the image capture. On saving this image a `image_processing.file_saved` event is fired, with a payload that includes:
#### Event `deepstack.file_saved`
If `save_file_folder` is configured, an new image will be saved with bounding boxes of detected `target` objects, and the filename will include the time of the image capture. On saving this image a `deepstack.file_saved` event is fired, with a payload that includes:

- `entity_id` : the entity id responsible for the event
- `file` : the full path to the saved file

An example automation using the `image_processing.file_saved` event is given below, which sends a Telegram message with the saved file:
An example automation using the `deepstack.file_saved` event is given below, which sends a Telegram message with the saved file:

```yaml
- action:
Expand All @@ -94,19 +97,19 @@ An example automation using the `image_processing.file_saved` event is given bel
id: '1120092824611'
trigger:
- platform: event
event_type: image_processing.file_saved
event_type: deepstack.file_saved
```

#### Event `image_processing.object_detected`
An event `image_processing.object_detected` is fired for each object detected above the configured `confidence` threshold. This is the recommended way to check the confidence of detections, and to keep track of objects that are not configured as the `target` (configure logger level to `debug` to observe events in the Home Assistant logs). An example use case for event is to get an alert when some rarely appearing object is detected, or to increment a [counter](https://www.home-assistant.io/components/counter/). The `image_processing.object_detected` event payload includes:
#### Event `deepstack.object_detected`
An event `deepstack.object_detected` is fired for each object detected above the configured `confidence` threshold. This is the recommended way to check the confidence of detections, and to keep track of objects that are not configured as the `target` (configure logger level to `debug` to observe events in the Home Assistant logs). An example use case for event is to get an alert when some rarely appearing object is detected, or to increment a [counter](https://www.home-assistant.io/components/counter/). The `deepstack.object_detected` event payload includes:

- `entity_id` : the entity id responsible for the event
- `object` : the object detected
- `confidence` : the confidence in detection in the range 0 - 1 where 1 is 100% confidence.
- `box` : the bounding box of the object
- `centroid` : the centre point of the object

An example automation using the `image_processing.object_detected` event is given below:
An example automation using the `deepstack.object_detected` event is given below:

```yaml
- action:
Expand All @@ -119,7 +122,7 @@ An example automation using the `image_processing.object_detected` event is give
id: '1120092824622'
trigger:
- platform: event
event_type: image_processing.object_detected
event_type: deepstack.object_detected
event_data:
object: person
```
Expand Down
9 changes: 3 additions & 6 deletions custom_components/deepstack_object/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
DEFAULT_API_KEY = ""
DEFAULT_TARGET = ["person"]
DEFAULT_TIMEOUT = 10
EVENT_OBJECT_DETECTED = "image_processing.object_detected"
EVENT_FILE_SAVED = "image_processing.file_saved"
EVENT_OBJECT_DETECTED = "deepstack.object_detected"
EVENT_FILE_SAVED = "deepstack.file_saved"
BOX = "box"
FILE = "file"
OBJECT = "object"
Expand Down Expand Up @@ -274,10 +274,7 @@ def name(self):
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
target = self._target if len(self._target) == 1 else "target"
if self._state is not None and self._state > 1:
return target + "s"
return target
return ""

@property
def device_state_attributes(self):
Expand Down

This file was deleted.

730 changes: 0 additions & 730 deletions development/Deepstack object detection.ipynb

This file was deleted.

Binary file removed development/black.jpg
Binary file not shown.
Binary file removed development/boxed_img.jpg
Binary file not shown.
Binary file removed development/family.jpg
Binary file not shown.
Binary file removed development/objects.jpg
Binary file not shown.
Binary file removed development/test-image3.jpg
Binary file not shown.

0 comments on commit e9ce502

Please sign in to comment.