Motion detection

Moderator: leecollings

Post Reply
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Motion detection

Post by Egregius »

thomasbaetge wrote: Friday 22 May 2020 11:35
Egregius wrote:
thomasbaetge wrote: Friday 22 May 2020 11:17 Additionally I'm running video surveillance with object detection on Synology (not surveillance station!), feeding messages into the system too.
A bit off topic but I'm wondering what u use for that? I'm using pikrellcam on rpi camera's because I don't want my Synology running 24/7.
Totally OT, because it's not even domoticz related:)
In a nutshell: my Synology runs 24/7 anyway, because I'm using it as VPN server.
All my cameras are WiFi IP cams. On movement detection, they upload pics to a folder on the Synology.
A local node red installation monitors the folder and feeds the snapshot into a tensorflow based object detection. If anything of interest comes out, I get a notification in telegram, including the snapshot and domoticz gets notified via MQTT.

I can provide more details if you'd like, but probably better in a different spot. I only mentioned it here, because this is way beyond the capabilities of a RPI (I tried...)

Gesendet von meinem Pixel 4 XL mit Tapatalk
Indeed best to start a separate topic for this.

If I understand it correctly you're using the basic motion detection of your camera's which kind of sucks. Therefor you analyze the images with another software to detect if it's a true object that moves or just change in light because of clouds etc. Correct?
As stated before, I use pikrellcam of wich the motion detection isn't bad but always could be better of course.
If you like you're more than welcome to explain your setup. I can easily add some stuff to the domoticz debian server.
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Motion detection

Post by thomasbaetge »

Cool :)

The way you summarised it, pretty much nails it :)
First of all, I'm abroad a lot of time and a couple of years ago, I had someone breaking into my house (he's still serving his prison sentence for that, thanks to the tech, police caught him on my premises), so there's 2 main focuses on my system: security and stability.

I tried a lot of surveillance stuff over the years, but none worked as I wanted.

So, for the current setup, I'm using a lot of outdoor webcams with night vision. Average stuff from Amazon really.
They all can upload pics on motion detection, mostly via FTP, but the detection, especially outdoors is really stupid, you get a lot of false positives from trees moving in wind or light changes.

A while ago, I came across tensorflow and some pretrained models, that can be run on suitable machines in docker.
On top of that there's already a node, to integrate this with node red:
https://flows.nodered.org/node/node-red ... t-exchange

So on my Synology I installed docker and 2 containers:
Node-red
https://registry.hub.docker.com/u/nodered/node-red/

Object detection:
https://registry.hub.docker.com/u/codai ... -detector/

I didn't use my existing node red installation, because I wanted to save some network traffic. This way it's all on the same machine.

After that, I wired these together, using only node red.
New snapshots are picked up by a file listener and are send to the object detection.
If the result is meaningful, i.e. a person or dog or cat or car...., The snapshot is sent to telegram and a dummy switch is triggered in domoticz (does nothing yet)

Since NR is not easy to access from the outside, I also have switches in domoticz, to enable/ disable cameras (like when we are outside in the garden).
Once a week, the snapshot directory gets cleared by a script, because it collects thousands of pictures in a day sometimes.

So far this is the best solution I found. It works really good, only a few false positives, it's running on a machine, that's already up anyway and there's no license costs no cloud and you can literally use any camera.

One additional point: I'm using a dedicated 2.4ghz WiFi network for all IOT stuff, so my regular network stays clear for regular use.





Gesendet von meinem Pixel 4 XL mit Tapatalk

thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Motion detection

Post by thomasbaetge »

Additionally: if someone else has a different setup, that works good, I'd like to know. I'm always up for new ideas and my system keeps growing and changing all the time ;)

Gesendet von meinem Pixel 4 XL mit Tapatalk

thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Motion detection

Post by thomasbaetge »

So, I found some time today, so here is a bit more detail.

this is the flow for 2 of my cameras in the same area:

Code: Select all

[{"id":"34f442bf.3ae45e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"6c8a1442.f4537c","type":"debug","z":"34f442bf.3ae45e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":200,"wires":[]},{"id":"fb9d0ad8.f7c7a8","type":"file in","z":"34f442bf.3ae45e","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":790,"y":80,"wires":[["bcfc2591.afcca8"]]},{"id":"bcfc2591.afcca8","type":"object-detector","z":"34f442bf.3ae45e","service":"672f334e.0e285c","method":"predict","passthrough":false,"annotated_input":"","predict_body":"","predict_bodyType":"str","predict_threshold":"0.7","predict_thresholdType":"str","name":"","x":240,"y":200,"wires":[["8fab9227.913ea"]]},{"id":"2377db36.2d3734","type":"function","z":"34f442bf.3ae45e","name":"filename","func":"msg.payload = msg.filename\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":80,"wires":[["fb9d0ad8.f7c7a8"]]},{"id":"a309922b.de5ab","type":"watch-directory","z":"34f442bf.3ae45e","folder":"/Terasse","recursive":false,"typeEvent":"create","ignoreInitial":true,"ignoredFiles":"","name":"","x":120,"y":40,"wires":[["b84e224a.968b5"]]},{"id":"80b2f20f.5ef65","type":"watch-directory","z":"34f442bf.3ae45e","folder":"/Einfahrt_hinten","recursive":false,"typeEvent":"create","ignoreInitial":true,"ignoredFiles":"","name":"","x":140,"y":100,"wires":[["496acaa4.9e36e4"]]},{"id":"8fab9227.913ea","type":"function","z":"34f442bf.3ae45e","name":"Filter","func":"var excl = \n[\n\"bird\",\n\"tv\",\n\"chair\",\n\"book\"\n]\n\nvar x = excl.includes(msg.payload)\nif (x === false && msg.payload !== null)\n\n\n{\nreturn msg;\n}","outputs":1,"noerr":0,"x":490,"y":200,"wires":[["6c8a1442.f4537c","724b1aa8.96c6a4","b6a77532.05a598"]]},{"id":"724b1aa8.96c6a4","type":"function","z":"34f442bf.3ae45e","name":"Domoticz message","func":"  msg.payload = {\n    \"command\": \"sendnotification\",\n    \"subject\": \"Object Detection\",\n    \"body\": msg.filedir.replace(\"/\", \"\") + \" \" + msg.payload + \" detected\",\n    \"priority\": 0}\n\nreturn msg;\n","outputs":1,"noerr":0,"x":640,"y":300,"wires":[["f45dd354.078c2"]]},{"id":"f45dd354.078c2","type":"mqtt out","z":"34f442bf.3ae45e","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"d04b4d92.652e5","x":810,"y":300,"wires":[]},{"id":"b6a77532.05a598","type":"function","z":"34f442bf.3ae45e","name":"Send the snapshot","func":"// sendMediaGroup example: send  between 2 and 10 media.\n// Note that type can also be video.\n// and the caption property is optional.\n// see https://core.telegram.org/bots/api#inputmediaphoto\n// see https://core.telegram.org/bots/api#inputmediavideo\nmsg.payload = {}\nmsg.payload.chatId = \"-1001452905938\"\nmsg.payload.type = \"mediaGroup\";\nmsg.payload.content = [\n    {\n        type : \"photo\",\n        media : msg.filename,\n        caption : \"Snapshot\"\n    }\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":380,"wires":[["89d22f2a.402b7"]]},{"id":"89d22f2a.402b7","type":"telegram sender","z":"34f442bf.3ae45e","name":"","bot":"b416a6a4.700ef8","x":850,"y":380,"wires":[[]]},{"id":"84f0761e.89b638","type":"inject","z":"34f442bf.3ae45e","name":"","topic":"","payload":"{\"command\":\"getdeviceinfo\",\"idx\":374}","payloadType":"json","repeat":"1800","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":460,"wires":[["586c6c8e.cee2f4"]]},{"id":"586c6c8e.cee2f4","type":"mqtt out","z":"34f442bf.3ae45e","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"d04b4d92.652e5","x":350,"y":460,"wires":[]},{"id":"34dac0e5.35db5","type":"mqtt in","z":"34f442bf.3ae45e","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"d04b4d92.652e5","x":140,"y":540,"wires":[["bc102314.a634a"]]},{"id":"78279b44.fc6484","type":"debug","z":"34f442bf.3ae45e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":540,"wires":[]},{"id":"bc102314.a634a","type":"json","z":"34f442bf.3ae45e","name":"","property":"payload","action":"","pretty":false,"x":330,"y":540,"wires":[["618f634c.0fe2ec"]]},{"id":"618f634c.0fe2ec","type":"function","z":"34f442bf.3ae45e","name":"","func":"if(msg.payload.idx == 374)\n{\nflow.set(\"CamTerasse\", msg.payload.nvalue)\n\n}\nif(msg.payload.idx == 375)\n{\nflow.set(\"CamPool\", msg.payload.nvalue)\n\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":540,"wires":[[]]},{"id":"b84e224a.968b5","type":"function","z":"34f442bf.3ae45e","name":"Switch","func":"var on = flow.get(\"CamTerasse\")||0\nif (on == 1)\n{\nreturn msg;\n}","outputs":1,"noerr":0,"x":390,"y":40,"wires":[["2377db36.2d3734"]]},{"id":"496acaa4.9e36e4","type":"function","z":"34f442bf.3ae45e","name":"Switch","func":"var on = flow.get(\"CamPool\")||0\nif (on == 1)\n{\nreturn msg;\n}","outputs":1,"noerr":0,"x":390,"y":100,"wires":[["2377db36.2d3734"]]},{"id":"672f334e.0e285c","type":"object-detector-service","z":"","host":"http://192.168.2.11:5011","name":"TBADS"},{"id":"d04b4d92.652e5","type":"mqtt-broker","z":"","name":"Controlberry","broker":"192.168.2.40","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b416a6a4.700ef8","type":"telegram bot","z":"","botname":"TBA.Domoticz","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

it requires some additional nodes:
node-red-contrib-model-asset-exchange
node-red-contrib-telegrambot
node-red-contrib-watchdirectory

I am running all of this on a Synology 716+II

for Docker in Synology you need these:
Anmerkung 2020-05-23 140636.jpg
Anmerkung 2020-05-23 140636.jpg (100.47 KiB) Viewed 2073 times
as for the object detection, you may need to choose not the latest image but a previous one, due to restrictions in the processors command set. start with a high version and if you get an error running it, work your way down.

the rest is simple:
Configure your cams to upload pics to a directory on the synology upon motion detection. I am using FTP for that, as my cameras all support that.
it will upload a lot of stuff but only those with detected objects will give you a notification.
during testing you may need to adjust the function node named 'filter' to rule out those objects you don't want.
I did it 'trial and error'.

enjoy :)
lost
Posts: 660
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Motion detection

Post by lost »

thomasbaetge wrote: Friday 22 May 2020 15:02 Additionally: if someone else has a different setup, that works good, I'd like to know. I'm always up for new ideas and my system keeps growing and changing all the time ;)
Hello,

For the basics:
-Using camera embedded motion detection as a pre-filter (limits LAN bandwith usage...).
-A service that monitors FTP cam subdirectories (in a tmpfs) for new images and do some post processing (inside a 10s loop for responsiveness)...

My setup looks like yours.

Main difference is I wanted to keep everything running on the single raspberry PI3 that manage my home an dis the only "computer" running 24/7.

So there's no IA for object recognition etc... I so had to keep post processing simple.

Anyway, as I only have external cameras monitoring my home front/rear + garage (nothing inside, even if they are not accessible directly on the internet I don't want to have any micro/cam inside), I runned in the usual issues: Trees/sun/wind... cats passing-by. Worse case may be with spiders or even birds thinking the cam lens may be a nest and sticking there for a few seconds.

As the PI was already managing my alarm system, with some external PIR sensors also likely to sometime send false positives (less likely than cams, but I already had to take care of this), I had a weight additive (on 1mn time slice) based system in place: One sensor, internal or external = different base weight.

Internal sensors had a base weight = siren trigger weight.
External sensord base weight < siren triger, so several sensors must trigger or re-trigger in the time slice to reach siren trigger.

With some tuning on base weights, this proved reliable.

With the cams, the same idea was used. Difference is the FTP file presence triggers a virtual PIR in domoticz, not real hardware, and added weight is a function of FTP image files number retrieved in a FTP check time slice (10s).

And that was enough to fit easily in my existing alarm system and not needing too much horsepower.

If needed, in case of doubt, all images captured in a FTP check time slice are emailed inside a password protected 7z archive to a dedicated gmail account. So I can check them if needed and if this was someone breaking-in, the bad guy can go away with the hardware, the images are already out... The FTP loop also feeds a Domoticz custom page (that is build at FTP monitoring service start, for every registered cams, automatically using yattag as the service is written in python) with last captures downsized & merged, to easily figure-out what's going on remotely if needed.

For now, this gets the job done. If a future raspberry version integrates a NPU able to do better (+better storage option than a SD, even if with some tuning I managed to make it reliable), I may consider upgrading my system!

Problem is I need IP cams freely configurable (http, not a smarthone app), with some minimal motion detection requirements (zone selections with different sensitivity) and able to deliver image files as fast as the cam is able to capture them (not a fixed 10s video stream, for instance, that'll not fit with my weight mechanism).

A few years ago, this was quite common. But now, this is not as the internet access is now mostly a dumbphone thing...

Still have a few Dahua references in the 40/80€ price range (depending on device size, I have some cams that just can't be seen if you don't know were they are, not even using IR at night) I ordered from ali, 2MPix/Starlight ones have very impressive low light sensitivity (this goes worse with 4/6Mpix that are also availlable) and they fit my needs for my system.They now replace my old VGA ones when I have time to install them.
Justina
Posts: 1
Joined: Thursday 17 December 2020 8:52
Target OS: Windows
Domoticz version:
Contact:

Re: Motion detection

Post by Justina »

You need a Motion Sensor for each room you would like to protect. The Motion Sensor will not “look” through walls. You can point Motion Sensors at each other – this is not a problem. The burglar alarm will sound if anyone walks within range of your Motion Sensors.










MyBPCreditcard
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest