Page 224 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 224
PDA 10 5/27/03 8:51 AM Page 200
// Scan through the frames comparing the last to the new
// PDA Robotics
long same_count = 0;
for ( DWORD i = 0; i < lpVHdr->dwBytesUsed; i++ )
{
if( *frame_data == *last_frame_data )
{
same_count++;
}
frame_data++;
last_frame_data++;
}
//
// Reset our pointers or we are wading through deep @#*!
//
frame_data = (BYTE *) frame_data_start;
last_frame_data = (BYTE *) last_frame_data_start;
if( frames_sampled < 5 )
{
if(frames_sampled > 0 )
{
frame_same_total += same_count;
average_frame_similarity = frame_same_total / frames_sampled;
trigger_threshold = ( average_frame_similarity / 30 ) *
global_detection_threshold;
}
frames_sampled++;
}
//
// If the slider has been moved recalculate
//
if( recalculate_threshold == 1 )
{
trigger_threshold = ( average_frame_similarity / 30 ) * global_detection_threshold;
recalculate_threshold = 0;
}
//
// Note : If sound capture is activated you can detect the *wave*
// cap_params.fCaptureAudio = TRUE;
//
//
// If we are over the threshold then motion has been detected
200