Zone minder patches

Various patches for the zone minder application.


A better motion detection patch. motion-1-2.diff 

Diff verses 1.23.2 zoneminder-1.23.2-local.patch 

 Add-on to above to maybe fix crasher: crash-fix.diff

Next version: zoneminder-1.23.3-motion-2.diff 

 Next version: zoneminder-1.23.3-motion-3.diff

Next version: zoneminder-1.23.3-motion-4.diff

Next version: zoneminder-1.23.3-motion-5.patch


Next version: zoneminder-1.23.3-motion-6.patch 

* added decimation. Motion detection runs on 1/4 size images for lower CPU utilization.

I'm running these with 640x480 cameras, at 10 frames per second. I'm using a transparency value of 10 %, and an alarm frame count of 10. 

At these values, it's pretty good with picking up events, and ignoring noise. Most of my false alarms come from the cameras going beserk: For some reason, they occasionally dial up the sensitivity so high the image goes mostly white, and then step it back down over the space of about 15 seconds. 

Needless to say, that raises an alarm!


An example. A camera is watching this door.


The top image is what the camera is currently seeing; The bottom image is the 'noise mask' that the motion detector has built up over time. White areas are places that the motion detector will ignore (the brighter, the greater the difference it will ignore). This camera is an MJPEG camera, and you can see that it's learned where the JPEG noise in the image normally falls.

Hacky script to convert zoneminder events into MPEG, joining events where they're "close enough": convert-events-to-mpeg

My current to-do list. (2008-Jun-22)

(estimated completion date: sometime in 2012).

1. Implement decimation. Carry only a 160x100 blended image (instead of a full size image) which reduce the data enough that it's practical to do some more expensive maths.


2. Implement a median filter now that there's a small enough amount of data. This would help a lot in reducing point noise in low-light situations, and with noisy cameras.


3. Re-structure the motion detection so that it's a plugin that receives a split of the motion stream, that it then labels behind the fact. (i.e. the plugin effectively see now +/- 15 frames or similar). This will hopefully be a relatively general architecture for other plugins.


4. Preserve the original data stream. This one is a big change. Right now , zoneminder takes JPEGs from my cameras, uncompresses them, throws them around in memory among 3 processes and then re-compresses them again. This is costly in terms of CPU and memory. I'd like to have zoneminder simply store the original JPEGs in a ring buffer, and then drop them out to disk without decompressing and recompressing when an event occurs.

 This would drastically reduce memory usage, and slightly reduce CPU.

This would also complicate things like the mythtv zoneminder plugin (which I currently use), but it may make it substantially better by being able to feed an mpeg-2 stream to zoneminder for lower network usage (and lower CPU on the zoneminder side).

Would also enable having audio as part of the data stream! (A top request from my wife).


5. Valgrind. There's a memory leak in zma somewhere that I can't pin down. I'm fairly sure that my code didn't add it, it's just triggering it.


6. Use the plugin architecture to do a trainable network to further suppress false alarms.  Trick here is to do enough data reduction that training a network is practical. My first guess is to do something like bucketed histogram, plus/minus 5 frames, plus frame energy and variance. This arises from my most frequent source of false alarms: Cameras adjusting light levels, and sun/overcast changes.


7. Add mpeg-4 support. I've an mpeg-4 camera that I currently convert to MJPEG, but the mpeg-4 is lighter. And my future cameras are likely to be AVCHD which is even worse to deal with.

This will almost certainly require adding the ffmeg libraries. Which are horrible to deal with, so it would almost certainly take just adding the source for ffmpeg to zoneminder (which everyone else seems to do!). But it would instantly make zoneminder much more capable about dealing with video sources.



Anyway: That's my todo list. Brave ambition considering the paltry patch I've currently done. :)