Object detection for video surveillance

Clear!

Ok, I need to tune :-)… thereis a person in the garden with plant hair and the car is not detected :slight_smile:

Right, sometimes the detection model is not very accurate. The filters of higher confidence and bigger area can level such flaws.

One of my cameras won’t revert back to 3fps after no movement for 30 seconds. It won’t even work if I manually trigger the animation.

I think 15fps for a prolonged period is maybe the cause of my performance issues.

Any suggestions? Any other way to force it back to 3fps other than mqtt?

EDIT: I think this might work but hard to test as i need to wait until it goes wrong.

  - alias: "Garden FPS Failsafe"
    trigger:
      - platform: numeric_state
        entity_id:
          - sensor.garden_detection_fps_in
          - sensor.driveway_detection_fps_in
        above: 4
        for: 
          minutes: 5
    action:
      service: mqtt.publish
      data_template:
        topic: "watsor/cameras/{{ trigger.to_state.object_id.split('_')[0] }}/command"
        payload: "FPS = 4"
        qos: 1
        retain: true

It won’t work in case the object hits the frame as the application drop FPS limit as soon as something is detected.

Better to check, whether binary sensor works as expected. Maybe boolean logic needs to be split on two automations - one for each of 2 cameras.

I split it up into separate automation for each camera and it did work at keeping the fps down as I am still having the same problem. But, it fired alot more than it should have. i thought it would have only fired after motion was detected

out of curiosity - do you know why?

Take a picture, it explains why it’s fired. Increase the confidence or area filters to reduce false positives.

Hi there!

Loving this project, after much sweat and many tears (mostly due to Ubuntu drivers vs cuda toolkit vs tensorflow compatibility issues) I managed to get it running in a separate docker using Nvidia GPU and communicating with my home assistant via MQTT.

I have a few questions if you are able to help please:

  1. I assume there is no way to run on GPU from within Home Assistant using the HA addon? When I tried to run it from within HA, I specified cuvid in the configuration but it was using my CPU and resulted in much lower framerates

  2. I am using whatever model is bundled with the docker. However, it creates many false positives and does not always detect a person, especially when it’s dark. I tried increasing confidence limit but it is then less likely to detect a person at night (which is when I actually want it to be more accurate). I am running two cameras and my GPU use is less than 30% and the frame rates are 20-25 FPS so there is plenty of room for more complex processing.
    I don’t really understand Tensorflow yet as this is my first exposure to it, so please forgive me if this is a silly question but is there a way to use a more complex model that can utilize more of the GPU power and produce more accurate results? If it’s possible, are you able to recommend a model I should use?

Thanks!

Yeah, using docker image is the easiest way to run it, especially on GPU, where it helps to avoid complex setup.

  1. That’s right. HA OS and supervisor don’t support GPU accelerated Docker containers yet.

  2. MobileNet v2 is the default model in Docker image. But Inception v2 can provide better accuracy. To switch the model: unpack the archive, rename the file to gpu.uff and mount the volume at /usr/share/watsor/model.
    If your GPU supports Half precision (also known as FP16), you can boost performance twice as much by enabling this mode.

That’s awesome thanks, working much better already.
GPU is using 40% now, I still have one more camera to add later on so it should be comfortable.
The GPU is a GTX965m so I dont think it supports FP16…

Regarding video storage, is there anyway to start video when object of interest is detected then stop recording after, for example, 2 minutes of no objects being recognized again? And create a new file for each instance, then delete the oldest file in the system once a certain total folder size limit is reached? Currently it looks like one file is created and Watsor just writes the full stream into it so the file size grows big very quickly.
If that’s too complicated, what would be the best way to send or save snapshots for Home Assistant use?

Actually it looks like it’s possible to use Home Assistant to do the recording, uploading to Google Drive and clean up old recordings. I got the processed stream running in HA now, so just need to automate the recording part when relevant MQTT is sent from Watsor.
Still get some false positive on the rear camera where there is no street light etc (the front seems to be pretty reliable so far).
I appreciate it’s a difficult task for Tensorflow to do this at night, any ideas how I can improve it at all possible?
Capture

is there anyway to start video when object of interest is detected then stop recording after, for example, 2 minutes of no objects being recognized again?

I use the combination of an app in appdaemon and ffmpeg. The app subscribes to the detection events and runs ffmpeg. The latter records short segments up to 2 minutes and expands the segment filename with date and time. Another script can purge the stale files on schedule.

Still get some false positive on the rear camera where there is no street light etc (the front seems to be pretty reliable so far).

Yeah, the models are not perfect. Some people plug more tools in the detection chain, such as Deepstack, so that once Watsor has detected something, the image is then refined with the better model (may be RCNN) to do a confirmation pass prior to alarm. HA ties everything together at that.

I tried the Home Assistant recorder service but can’t get it to work properly. Very unreliable and leaves a lot to be desired (at least for my use case).
I will try out your code, looks great!

Also, thanks for Deepstack suggestion, haven’t seen it before and it looks like a great way to expand functionality for face recognition.

Hello :slight_smile:

I have tried this on a raspberry pi 3 with the Coral accellerator. Seems to be working :+1: … The camera is currently set at 10FPS. At this setting, things seem to work, but if I add another camera it doesnt seem to be able to keep up. (Watching the video is sluggish).

What is to be expected using an Rpi 3 and the Coral? Does one camera at 10FPS seem reasonable?

Yes, ~ 10 FPS is all you can get on a Rpi 3 with the Coral.
Here is the performance comparison: https://www.youtube.com/watch?v=TiOKvOrYNII

please help me
I installed and got this error
MainThread root ERROR: [Errno 2] No such file or directory: ‘/etc/watsor/config.yaml’
here is my configuration
watsor:
container_name: watsor
image: smirnou / watsor: latest
environment:
- LOG_LEVEL = info
volumes:
- / etc / localtime: / etc / localtime: ro
- / etc / watsor: / etc / watsor: ro
devices:
- / dev / bus / usb: / dev / bus / usb
- / dev / dri: / dev / dri
ports:
- 8088: 8080
shm_size: 512m
have a lucky day