AI motion detection with BlueIris: an alternate approach

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
Note: I will no longer be providing release updates or responding to questions on this thread. If you would like to stay up-to-date on releases you can subscribe to release notifications on the github project. For support open a github support issue.

A few weeks ago I came across The Hook Up's video on how to use gentlepumkin's now famous thread to set up AI motion detection with BlueIris. This sent me down the path of building a new PC, buying BlueIris, migrating all my IP cameras from Synology Surveillance Station, and getting the AI Tool up and running.

While I eventually did get everything working and saw the potential I wanted something that could run as a Docker container. I also missed not having MQTT notifications as part of the system. I know it's possible to set up BlueIris to do the MQTT sending but I wanted the messages earlier in the flow so I could use Home Assistant + NodeRed to decide when it was appropriate to turn on high-resolution recording (e.g. if I'm outside enjoying my deck I don't need the HD feed constantly triggering).

I'm happy to release node-deepstackai-trigger, a Docker image that offers:
  • AI detection using DeepStack.ai (inspired by gentlepumpkin's idea and initial implementation)
  • Initial configuration and installation with just two files
  • Mask regions to block sections of the image that are prone to false positives
  • Support for web requests to trigger BlueIris camera recording
  • Support for sending MQTT messages, including motion end events for nice integration with Home Assistant MQTT binary sensors
  • Support for sending Pushbullet, Pushover and Telegram messages
  • REST API for activating a trigger from an external system and retrieving statistics
  • MQTT topics for activating a trigger from an external system and retrieving statistics
From the start I worked hard to make installation and configuration as quick as possible. If you already have your BlueIris cameras configured for the AI Tool solution then you just need to copy two files locally to your machine, define your triggers in the configuration file, then run docker-compose up. There's no need to independently install or configure Deepstack.ai: it's all taken care of for you. (If you already have Deepstack.ai running as a container you'll want to stop it to save CPU time. No need to have two copies running!)

Interested in taking it for a spin? Quick start instructions are available in the readme. Complete instructions are on the project wiki, including a complete write-up of the different configuration options and detailed steps for setting up cameras in BlueIris if you haven't done so already.

Hope you find this useful!

P.S. If you're the type that likes to hack at code the project is designed to get up and running for development in less than five minutes. See the contributing guide for the magic. Happy hacking!
 
Last edited:

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
I updated this on Sunday to support installation on Synology/UnRaid/whatever your preferred Docker host is without relying on docker-compose being available. Enjoy!
 

spuls

n3wb
Joined
May 16, 2020
Messages
29
Reaction score
20
Location
at
How did you share the pictures with the container, simple via smb?
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
This will probably work with Motion Eye also, nothing you have is specific to Blue Iris except the documentation. Great work!
Yup, there's nothing BlueIris specific in the code at all. As long as you give it a folder of images to work on then it'll do its thing and fire off web requests, MQTT, or Telegram notifications.
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
How did you share the pictures with the container, simple via smb?
The images are mounted into the container using the docker-compose.yml file. The folder of images must exist on the machine that Docker is running on. In my case the machine running BlueIris and the machine running Docker are the same, so it's a simple local folder. If you have BlueIris running on a different machine then you would smb share the folder to the machine running Docker, then mount the folder into Docker.

Hope that helps!
 

sn0000py

Young grasshopper
Joined
Dec 30, 2019
Messages
41
Reaction score
5
Location
Austria
Hello :D
i have just tested it and runs nice :D

  • how big are your Image size? (in Bytes and in pixels?)
  • and how long does it take for deepstack to process the file?
  • Where run your Docker? Windows/Linux?
I have running it on the Windows 10 System, the file is 571kb with 3840*2160 pixel, deepstack need between 1,5 and 2 seconds
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
Glad you got it working!

I'm using 640x480 images, they're about 200kb and take a second or less to process. You don't need to do the full HD image for recognition, if you configure BlueIris as documented in the project wiki you can use the SD substream feed to generate the images and then trigger an HD feed for recording when motion is detected.

I'm running it on Windows 10 on the same machine that BlueIris is on.
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
I just published a new version, 1.6.0, with some minor bug fixes and less stringent checks on the watchedObjects list (case doesn't matter anymore). There are no breaking changes or modifications to the configuration files.

If you're running this just do "docker-compose pull" inside the directory with your docker-compose.yml file, then do "docker-compose up" (or up -d for background running) to restart with the new image.
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
Version 1.7.0 is now available. The MQTT message now includes "state: on", and a second "state: off" event is fired after a (configurable) delay with no other motion detected. This simplifies the process of creating custom MQTT binary sensors in Home Assistant that accurately record motion in HA history.

Sample Home Assistant MQTT binary sensor that takes advantage of this new functionality:

YAML:
platform: mqtt
device_class: motion
name: "Front door motion"
state_topic: aimotion/triggers/FrontDoor
payload_on: "on"
payload_off: "off"
value_template: "{{value_json.state}}"
To upgrade do "docker-compose pull" inside the directory with your docker-compose.yml file, then do "docker-compose up" (or up -d for background running) to restart with the new image. The new version defaults to 30 seconds before sending the off event. To change this add an "offDelay" property to the MQTT trigger configuration.
 

JNDATHP

Getting comfortable
Joined
Oct 16, 2018
Messages
625
Reaction score
1,291
Location
USA
So I have a Win 10 machine that is running deepquest and BI5. Do I install docker desktop?
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
Does docker+deepstack run as a service?
It runs in the background, yes. The config file included as a sample also enables auto-restart, so if your PC reboots everything will come back up on its own automatically.
 

gazoo

n3wb
Joined
Dec 11, 2017
Messages
27
Reaction score
0
I'm literally cursed. Docker doesn't start right:

Docker.Core.HttpBadResponseException:
Unhandled exception: job failed with message: 'DockerDesktopVM' failed to start. (Virtual machine ID BCA494C3-B6DA-4F21-B343-3743516F511B)

The Virtual Machine Management Service failed to start the virtual machine 'DockerDesktopVM' because one of the Hyper-V components is not running (Virtual machine ID BCA494C3-B6DA-4F21-B343-3743516F511B).
at Docker.Core.Logging.ClientExceptionInterceptor.<InterceptResponseAsync>d__0.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.Core\Logging\ClientExceptionInterceptor.cs

I CAN'T WIN
 

Splat

n3wb
Joined
Jun 8, 2020
Messages
9
Reaction score
7
Location
Australia
Thanks neile for your work on this it looks fantastic! The setup has worked fine and I got up and running very quickly.

I've spent time fine-tuning a node-red flow so +1 for this also. The code seems to work efficiently too.
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
I CAN'T WIN
Sounds like you don't have virtualization enabled on your computer's CPU. I hit this pretty regularly too on new desktop installs. You'll need to find out how to turn that on in your computer's BIOS. For Intel CPUs it's usually pretty obvious and labeled as "Hyper-V" or "Virtualization" in the BIOS. For AMD CPU's it's named something completely obnoxious (I can't recall off the top of my head) but it is there. I know because I went through this for my BlueIris install a few weeks ago on a new AMD-based machine
 

neile

Getting the hang of it
Joined
May 15, 2020
Messages
132
Reaction score
66
I've spent time fine-tuning a node-red flow so +1 for this also. The code seems to work efficiently too.
Nice! What kind of node-red flow are you using?
 

Splat

n3wb
Joined
Jun 8, 2020
Messages
9
Reaction score
7
Location
Australia
Nice! What kind of node-red flow are you using?
So far it sends a message to my google home mini announcing the detection based upon the prediction results and the match percentage. My aim is to log it and use some reporting on "traffic flow" on the road I live on. I'm looking to see if Telegram can support using the object detected and percentage in the image caption also as well as highlight the detection area in the alert. So many opportunities! Thanks for the start.
 
Top