Blob detection code
Posted: Tue Oct 25, 2005 7:17 pm
Hi,
to understand how the motion detection works I have had a look at the source code, namely zm_zone.cpp. I don't understand the part which handles the detection of blobs so I would appreciate if anybody could give me the big picture what the code does.
I'm talking about the code after (line 211)
What does bsx, bsy, bsm, bss stand for? BlockStat...?
Now, pdiff contains a pointer to a pixel of the picture, right?
The two for-loops around this statement are iterating over the zone.
Checks whether the current pixel has changed (WHITE) or not (BLACK). The prior processing changed the picture so that there are only black and white pixels.
So I don't understand this. lx contains the information if the left pixel is black or white and it is considered being black if it is not in the zone. That's the same with ly. But either lx=0x00 or lx=0xff since that's the definition of BLACK and WHITE.
I can't see what the check "if ( lx == ly )" does. There are the conditions "if (ly)" and "if (lx)" before so if the programm reaches this check it is every time true and the else clause is never executed. Or is it possible that lx is neither 0x00 nor 0xff?
Thanks,
hajo
to understand how the motion detection works I have had a look at the source code, namely zm_zone.cpp. I don't understand the part which handles the detection of blobs so I would appreciate if anybody could give me the big picture what the code does.
I'm talking about the code after
Code: Select all
if ( check_method >= BLOBS )
Code: Select all
BlobStats *bsx, *bsy;
BlobStats *bsm, *bss;
Code: Select all
pdiff = diff_image->Buffer( lo_x, y );
The two for-loops around this statement are iterating over the zone.
Code: Select all
if ( *pdiff == WHITE )
Code: Select all
lx = x>lo_x?*(pdiff-1):0;
ly = y>lo_y?*(pdiff-diff_image->Width()):0;
if ( lx )
{
//printf( "Left neighbour is %d\n", lx );
bsx = &blob_stats[lx];
if ( ly )
{
//printf( "Top neighbour is %d\n", ly );
bsy = &blob_stats[ly];
if ( lx == ly )
{
//printf( "Matching neighbours, setting to %d\n", lx );
// Add to the blob from the x side (either side really)
*pdiff = lx;
bsx->count++;
if ( x > bsx->hi_x ) bsx->hi_x = x;
if ( y > bsx->hi_y ) bsx->hi_y = y;
}
else
{
I can't see what the check "if ( lx == ly )" does. There are the conditions "if (ly)" and "if (lx)" before so if the programm reaches this check it is every time true and the else clause is never executed. Or is it possible that lx is neither 0x00 nor 0xff?
Thanks,
hajo