Face and person detection with Deepstack - local and free!

Well the state of the sensor is limited to the counts of the target, but in the summary attribute you get the number of each class. You can break out attributes using a template sensor.
I guess you want to detect new people/vehicles, but remember you get the count of objects, but this doesn’t tell you if they are the same object.

Re combining images, that sounds complicated, but you could to it in python of course

1 Like

Hi Rob, I’ve been searching most of the afternoon for the solution but I can’t find an answer so I hope you don’t mind if I ask you. How do I break out the attributes of image_processing.object_detected with a template ? I’ve looked here : https://www.home-assistant.io/integrations/template/ but that only deals with objects that have entity_ids. Or I can’t see the wood for the trees :roll_eyes:

Use the template tool to experiment:

Note that this works fine for summary but to my surprise not for the predictions - will need to change the implementation slightly

That’s probably what was confusing me, I wasn’t getting what I was expecting using this method.

OK released v1.9 which drops the predictions as json and addresses a couple of minor issues in the UI. The sensor state is now a numerical so will be graphed correctly, and the time string is easier to read.

So I had a release frenzy, and we are now at v2.1. I have been trying really hard to get the overall experience using the component as simple as possible for the typical user, whilst exposing the full capabilities for power users. This has culminated in an approach where the UI and sensor attributes are ideal for typical users, and the event data is available for power users who want to do things like track multiple object types, or setup zoning of detections. Any feedback let me know. Unless there are any major issues with the changes this should be stable going forward. I will write up an article on how to exploit the full functionality allowed by events.
Cheers

Streamlined UI:

Event data:

2019-10-11 06:14:52 <Event image_processing.object_detected[L]: entity_id=image_processing.deepstack_object, object=dog, confidence=99.9, box=[0.559, 0.674, 0.842, 0.83], centroid=[0.752, 0.701]>

3 Likes

Your on fire, these look like great additions. Will fire this up some time this weekend. Sorry for the wall of text below.

In its current form this is already a functional tool, I would just like to comment on two things which I am sure you have given thought to and I am not sure if this going away of the intent of this tool. They go to the fact that like myself it sounds that a major use case of this is for an alarm/notification trigger:

(1) more important:
Allowing for the target to be multiple objects - One thing I am still trying to work around is the ability to trigger a save file event based on multiple targets without having to call the service twice, which goes towards processing efficiency as well as in a moving environment combined with the delay in motion sensing triggers the limited opportunity to capture the object. When this number grows to three or four objects it becomes impractical. In the example image what if I wanted to detect,save and notify with the snapshot image of either a person OR dog but only got the chance for one snapshot to process.

I may be interpreting this wrong but running a second instance to set up a second scan for dog will mean both image scan services need to be called when the image has already been processed however non main targets already filtered out.

Whilst the object_detected service has all of the details of the detection the save file event will only trigger on the main target.

(2) less important but useful from a security monitoring perspective:

Ability to ignore parts of the image - Many times a camera will show an image which has areas of interest and those which can be ignored. I can envisage it would be useful as in point 1 above to not only set multiple targets but for each target to set an include/exclude parameter to ignore based on x,y or even the centroid parameters. In security camera speak, think of it as a field event trigger. An example here is when a car is parked on the street in view of the camera, I would not want this to trigger the object detection/save file event. If it is in the area of interest (driveway) then proceed with the object detection save file event.

Again this could be observed through the object detection information passed but the save image trigger (which I find most useful) is very specific in terms of when it runs when having 1 target of a confidence threshold. Also, I just like boxes around dogs as well.


Again, I would just like to say that as it is now it is very practical, with the inclusions above it can very easily be used as quite a complex security monitoring system. I hope one day to contribute back with a write up on how this can be used for such purposes. Hope this helps.

Hi @xdss
both of those activities can in principle be achieved using the image_processing.object_detected event data, but we just need to figure out how to do it :slight_smile: If you are willing to experiment I think you will find solution to (2) quite quickly (for example using an python_script to process the bounding box info), and (1) combining images can also be achieved using a script but it is getting more complex.
Ultimately I could lump more and more features into the component, but then it becomes too complex for a typical user. So where there is a way using existing HA tools, that is preferred. For more specialised use cases there is also dedicated solutions like Shinobi.
Keep the feedback coming
Cheers

Don’t know if this will help but in my configuration.yaml I have the following (please ignore the names car / person, I’ve been experimenting)

 - platform: deepstack_object
   ip_address: 192.168.2.52
   port: 5000
   api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   timeout: 5
   scan_interval: 10
   save_file_folder: /config/www/deepstack_person_images
   target: car
   confidence: 50
   source:
     - entity_id: camera.gate1
       name: car_detector

Then I have this as an automation, it sends a message via telegram whenever a car, truck or person is detected but doesn’t require the service to be called multiple times. It’s a work in progress but perhaps you can build on it?

 - alias: Object detection automation
   trigger:
      - platform: event
        event_type: image_processing.object_detected
        event_data:
           object: car
     - platform: event
       event_type: image_processing.object_detected
       event_data:
          object: person
     - platform: event
       event_type: image_processing.object_detected
       event_data:
         object: truck
   action:
     service: notify.bot
     data_template:
       message: "{{ trigger.event.data.object }} with confidence {{ trigger.event.data.confidence }}"
1 Like

@robmarkcole
Hi Rob,
Have had both Deepstack Face and Facebox installed for a while, but just idly running, doing nothing in particular.
I now want to put them to better use, but can’t seem to see the save_file_folder option in face, just in object detection. Is there a technical reason for this as I would like to be able to view the last X number of faces detected.

Thank you

Thats not implemented yet for face

Hi,

Been following this thread with much interest, so thought I’d let you know what I’ve been up to:

I have Home Assistant hass.io running on a Raspberry pi 3b+.
I installed DeepStack with a NCS2 on a Raspberry pi 4 following these instructions -https://python.deepstack.cc/raspberry-pi
I’ve got the integration between HA and Deepstack working well harnessing Line Crossing notifications from a number of Hikvision cameras mounted around the house.
Still playing with automation of notifications etc.

Got a bit sidetracked with the idea that it would be nice to have HA and Deepstack running on the same raspberry pi. To this end, I installed Hassbian on the pi 4 and then installed Deepstack as above. So now I have an instance of HA and Deepstack running on a pi 4 and all seems well except I can’t get the instance of HA on the pi 3 to work with Deepstack as it did previously. I get a timeout errors in HA and no notification in Deepstack of the “detection” api being hit.

Any input into what I might be doing wrong or things to try greatly appreciated.

Thanks.

HI @nigel1
I agree it would be nice to have deepstack and HA on the same pi, good to know you already did this successfully on a pi 4. We are planning to support deepstack as a hassio addon in the future. I suspect this could be a specific issue for Hasspbian, perhaps they lock down the ports or something like that. The hasspbian discord chat might be a place to go for advice.
Cheers

Damn! Looking forward to testing! Nice work!

My use case is pretty simple.
Camera NVR (shinobi) detects motion. Use node-red to grab a snapshot and check the motion is from a person or car (avoiding wind moving trees, shadows etc) - as really I only care if a random person is somewhere near my house and less that a tree is moving lol. I currently manually save that file, but may move to your implementation.

I read you are looking to make an official integration. Haven’t played with your updates yet, but wondering if you could combine a single camera/image to have multiple targets, color bounding boxes differently. Save as a single file or different file?

image_processing:
  - platform: deepstack_object
    ip_address: localhost
    port: 5000
    api_key: Mysecretkey
    save_file_folder: /config/www/deepstack_person_images
    source:
      - entity_id: camera.local_file
        name: person_detector
        target: person
          show_bounding_box: true
          color: yellow
          save_file_prefix: person
        target: car
          show_boundjng_box: true
          color: red
          save_file_prefix: car

Not sure how useful that would be for folks though?

Either way, been using this for a while and LOVE it. In my mind your component is a key difference between an automated home, and a smart home! Thank you!

3 Likes

Thanks for your reply.
I believe the port is not an issue as I can reach the web ui on port 5000
I’ll do some digging.
Btw, any idea why the bounding boxes on images from one specific camera are mis-alligned (below) the identified person? Not the end of the world, just the perfectionist in me :grin:

Hey thanks for all your awesome projects on here! I noticed on your coral hit hub it’s archived.

Is that project dead? Did this replace it?

Thanks again.

@nigel1 where is your image? I notice sometimes bounding boxes are not perfect, but usually not far off.

@Darbos to coral is now integrated through my deepstack_object integration as described in the readme. Why duplicated work

Thank you. I thought that may be it. These two projects (deepstack and the usb accelerate project I linked) look the same just using different api servers? Is one preffered over the other, or faster? Thanks

It depends which hardware you have. Coral is using tensorflow-lite models which are less accurate but faster than the deepstack models. So it depends if you want:

  • Fast and tolerate lower accuracy, use coral
  • Slower but higher accuracy, use deepstack

Thanks, that clears it up perfect.

Im using a coral to watch my driveway and garage…and notify me if my car is in the driveway and not the garage when it is about to rain.

1 Like