Bug with md_get_cell_diff - CHDK Releases - CHDK Forum supplierdeeply

Bug with md_get_cell_diff

  • 3 Replies
  • 4105 Views
Bug with md_get_cell_diff
« on: 14 / February / 2008, 17:48:48 »
Advertisements
Since motion detection is in several builds I'll post this here.

The wiki docs say md_get_cell_diff will return a value between 0 and 255. But it can return negative values sometimes. The testing for motion (and threshold) is don't like so:
Code: [Select]
if(motion_detector.points[idx]>0){
motion_detector.prev[idx] = (motion_detector.curr[idx]-motion_detector.prev[idx])/motion_detector.points[idx];
tmp2 = ( motion_detector.prev[idx] < 0 ) ? -motion_detector.prev[idx] : motion_detector.prev[idx] ;
}

if( tmp2 > motion_detector.threshold ){
if (motion_detector.start_time+motion_detector.msecs_before_trigger < tick){
motion_detector.detected_cells++;
}
See how motion_detector.prev[] is updated to the cell's difference, but this can be negative if the previous cell's value was brighter than the current cell.
Then the tmp2 variable is used for the threshold test, but it's first made positive (absolute) for the test.

But md_get_cell_diff returns:
Code: [Select]
return motion_detector.prev[ MD_XY2IDX(column-1,row-1) ];In other words it returns the "raw" difference, which may be negative.
I guess the best way to fix this is to remove the tmp2 variable and do the threshold test on motion_detector.prev[] ?

Then again, thinking about it, it's actually useful the way it is since a script can check which way brightness has changed for an individual cell. For instance checking for a dark object moving across a brighter background, or visa versa. It just means the script will need a couple more lines if the abs difference is required.

*

Offline mx3

  • ****
  • 372
Re: Bug with md_get_cell_diff
« Reply #1 on: 14 / February / 2008, 23:17:56 »
so it can be negative.
do you think it is bug?

how else would you say brighter  or darker it is?

I think it is wiki to be fixed
« Last Edit: 14 / February / 2008, 23:23:01 by mx3 »
skype: max_dtc. ICQ: 125985663, email: win.drivers(at)gmail, eVB decompiler

Re: Bug with md_get_cell_diff
« Reply #2 on: 14 / February / 2008, 23:42:05 »
Well, the more I think about it, it's a feature as I described (telling which direction light intensity has changed). Maybe just update the wiki. If there were need to have it either way, then I guess md_get_cell_diff could be changed to something like:
Code: [Select]
int md_get_cell_diff(int column, int row, int AbsVal){
        int tmp;

      if (column<1 || column > motion_detector.columns){
return 0;
}

if (row<1 || row > motion_detector.rows ){
return 0;
}

        tmp = motion_detector.prev[ MD_XY2IDX(column-1,row-1) ];
        if AbsVal = 0 {
             return tmp;
        }
        else
        {
              return Abs(tmp);   
        }   
           

}

Which would be faster than doing it in a script.

*

Offline mx3

  • ****
  • 372
Re: Bug with md_get_cell_diff
« Reply #3 on: 14 / February / 2008, 23:46:49 »
..Which would be faster than doing it in a script.

it is possible to add one more optional parameter to md_cell_diff ubasic function
it would be backward-compatible
skype: max_dtc. ICQ: 125985663, email: win.drivers(at)gmail, eVB decompiler


 

Related Topics