Better motion detection?

Support and queries relating to all previous versions of ZoneMinder
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Post by mor »

SyRenity wrote:Thanks, I will try it.

One question though again - do I need to change anything in the zone settings? Or I can use the default values for new monitors?
The only change you may need to make it to reduce the 'Reference Image Blend %ge' to be 1.

The rest of the settings I confess are hard coded for now.
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Post by mor »

moOd wrote:Hi there! This is really interesting stuff!

I tried your patch on version 1.23.2, with some slight modifications on your diff-file (some entries seemed to be incorrect).. but I am expericing problems with the "zma".(...)

Did I something wrong?
No, I did. It's actually a patch versus 1.23.3. All the patches are versus 1.23.3

My apologies :( I had it in my head that the latest version was 1.23.2, but of course it's actually 1.23.3 and I diff'ed versus the latest version.

And that's why you'll get crashing and failed patches et al. So, just use the first patch I posted, and apply it to 1.23.3 and all should be well.

PS: If you look at http://www.dgmo.org/zoneminderpatches you can see an example noise mask that my system has 'learned'. In this example, it's learned to ignore diagonal lines in the image as they're very prone to JPEG noise.

(You can also see that it's learned to ignore the changing timestamp in the image! It's on my list to fix; the timestamp needs to be applied at a different point in the process).
moOd
Posts: 15
Joined: Tue May 13, 2008 9:53 pm

Post by moOd »

It's actually a patch versus 1.23.3. All the patches are versus 1.23.3
Thanks! :) Now the patching went through without errors.

I will try some more when I get home. Need to update the database and all that stuff before reporting.. (quick test showed in the log that ZMA was till crashing periodically)
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Post by mor »

moOd wrote: I will try some more when I get home. Need to update the database and all that stuff before reporting.. (quick test showed in the log that ZMA was till crashing periodically)
Umm. Hmm. Err. So it does :) Just grep'ed my logs and I can indeed see it crashed a few times today on one camera. But no core files generated. Ok, did the 'orrible chmod 777 /var/lib/zoneminder/www to see if it'll write a core file.

Hmm. This may fix the crash:

Code: Select all

--- a/src/zm_image.cpp
+++ b/src/zm_image.cpp
@@ -1011,6 +1011,19 @@ Image *Image::Delta( const Image &image ) const
 
        Image *result = new Image( width, height, 1 );
 
+       if ( !sq_buffer )
+       {
+               sq_buffer = new unsigned int[size];
+
+               unsigned int *pb = sq_buffer;
+
+               while( pb <sq_buffer>buffer;
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Post by mor »

Useless forum mangled patch. Try http://www.dgmo.org-a.googlepages.com/crash-fix.diff

Edit: Yes, that's almost certainly a fix. The problem is when a camera loses signal and re-acquires it, then ::Delta is called before ::Blend so things go away.
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Something that might interest you guys is the work of Andrew Kirillov:
http://www.codeproject.com/KB/audio-vid ... ction.aspx

He also has the aforge project at google:
http://code.google.com/p/aforge

His work is done in c# but the principals might be useful.
SyRenity
Posts: 301
Joined: Mon Jan 24, 2005 2:43 pm

Post by SyRenity »

Hi.
cordel wrote:Something that might interest you guys is the work of Andrew Kirillov:
http://www.codeproject.com/KB/audio-vid ... ction.aspx

His work is done in c# but the principals might be useful.
Indeed, I even posted about this a year ago here in forums. His 3rd method (http://www.codeproject.com/KB/audio-vid ... tion/3.jpg about half page) said to bring great detection quality, while significantly lowering CPU usage.

What he does, is basically pixelating the image before comparing it, thus lowering the number of pixels needed to be checked, and subsequently lowering the required CPU.

Mor, I wonder whether you can use it with your algorithm, and this way solve the increased CPU usage you mentioned.

(Btw, how exactly higher this usage then standard ZM method?)
User avatar
monex
Posts: 169
Joined: Mon Jan 22, 2007 1:10 pm

Post by monex »

Hi,

I found openCV for a while. It can be used for motion detection but can much more, for example face Recognition, gesture recognition and motion tracking. Maybe an integration into zoneminder would improve not only the motion detected but also the possibilities for a lot other exciting possibilities :)
Image
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

The only problem with openCV is it's dependency on ffmpeg. The requirement of ffmpeg would mean that fedora would no longer support our package in their repo or others like them. It would also mean that if anyone was to sell a system with ZM on it with ffmpeg being required, certain companies would be interested in going after someone for patent infringement which would not be good. Also their lib does not build in x86_64.

I'd love to see it, but I would not hold my breath, I too have been watching that project.
SyRenity
Posts: 301
Joined: Mon Jan 24, 2005 2:43 pm

Post by SyRenity »

Cordel, are you sure about the openCV dependency on FFMPEG?

AFAIK, if only plain images used (as here in ZM) it should be ok.
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Yeah, I'm sure :(
http://opencvlibrary.sourceforge.net/InstallGuide_Linux

It also will not build a working version on x86_64 :evil:
User avatar
monex
Posts: 169
Joined: Mon Jan 22, 2007 1:10 pm

Post by monex »

Hi,

it can be build without ffmpeg (otherwise opencv could not be build in the openSuSE build service due to ffmpeg http://software.opensuse.org/search?bas ... 1&q=opencv ) And it seems to build on x86_64 without problems (looks like there is at least the package for x86_64). But I don't know how useful opencv is without ffmpeg ;)
Image
moOd
Posts: 15
Joined: Tue May 13, 2008 9:53 pm

Post by moOd »

I patched ZM 1.23.3 with "zoneminder-1.23.2-local.patch" and also applied the "crash-fix.diff" patch from your homepage. Now everything is succesfully up and running without any crashes.

However.. my problem now is that it alarms as soon as I start it up. No matter what settings I apply in the zoning config for my camera, it instantly starts recording/detecting motion and never stops.
When I look at the recorded events, no blobs are shown at all and the stats looks like this:

Zone Pixel Diff Alarm Px Filter Px Blob Px Blobs Blob Sizes Alarm Limits Score
Backyard 255 146634 (100%) 0 (0%) 0 (0%) 0 0 (0%) 0,0-0,0 0

My source is configured to pull jpg images from an ip-camera ~2 fps (if that does matter?) and it worked fine before patching.
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Post by mor »

Ouch. That's what I get for hand-editing patches before posting.
Very sorry to have messed you around like this.

In zm_zone.cpp, line 201, there's a line that reads

Code: Select all

        if (pixel_avg > 2.50 && 0) {
It should read

Code: Select all

        if (pixel_avg > 2.50) {
Updated patch with this one-liner change is at http://www.dgmo.org-a.googlepages.com/motion-1-2.diff

It will also log the deviation values like

Code: Select all

May 15 08:08:00 localhost zma_m4[4511]: INF [Average 3.523838, pixels 39878 (10, 10, 10)]
May 15 08:08:00 localhost zma_m4[4511]: INF [Average 3.536901, pixels 39909 (10, 10, 10)]
May 15 08:08:00 localhost zma_m4[4511]: INF [Average 3.438239, pixels 38775 (10, 10, 10)]
May 15 08:08:00 localhost zma_m4[4511]: INF [Average 3.276509, pixels 38875 (10, 10, 9)]
May 15 08:08:00 localhost zma_m4[4511]: INF [Average 3.191593, pixels 37573 (9, 10, 9)]
Values above 2.5 after considered an alarm. The pixels is the number of pixels considered to be alarming, and the (r,g,b) are the average deviation in Reg,Green and Blue values (will be non-zero when the overall lighting levels change).

Edit: Hmm. And maybe apply this one too:

Code: Select all

diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp
index f1e59ec..49d5c1c 100644
--- a/src/zm_zone.cpp
+++ b/src/zm_zone.cpp
@@ -211,6 +211,7 @@ bool Zone::CheckAlarms( const Image *delta_image )
 #endif
                return( true );
        }
+       return false;
 
        if ( !alarm_pixels )
        {
Last edited by mor on Wed May 14, 2008 10:29 pm, edited 1 time in total.
mor
Posts: 45
Joined: Sat Apr 26, 2008 1:41 am

Post by mor »

moOd wrote: My source is configured to pull jpg images from an ip-camera ~2 fps (if that does matter?) and it worked fine before patching.
Note that at 2 fps, your system is going to learn fairly slowly. My values are all tweaked for about 15 fps. It's on my list to change all the frame rates to be 'time' rates so it's independent of the fps.

The key thing to watch for is that when you first time the system on, all the 'Average' values above should be trending down (assuming there's no motion happening!) until they drop under 2.5 at which point they should stop being logged.
Last edited by mor on Wed May 14, 2008 10:27 pm, edited 1 time in total.
Locked