atul
November 2, 2004, 13:12:11
Dear Stefan,
I tried computing the mean brightness and subtract it from each pixel. But i am unable to get the required results.
This code still considers the light flickering to be a motion and starts recording. I want to avoid this.
I am calculating the mean brightness of the current image and subtracting it from each pixel of the current image. same i do for the previous image. but i dont understand for the code to not work.
I am posting my source code in delphi for your reference. kindly take time to look into it and correct me if i am going wrong. I would be highly obliged if you put some time into this since its urgent to me.
below is my source code,
**************code snippet - Start***************************
//for no. of motion detect areas selected.
for iArea := 0 to MAX_MOTION_AREA - 1 do
begin
//variables initialised for each motion detect area
count := 0;
curBrightnessVal := 0;
keyBrightnessVal := 0;
CurMeanBrightness := 0;
KeyMeanBrightness := 0;
with WorkConfig.Camera[ACameraNo].MotionDetectArea[iArea] do
begin
//calculates the mean brightness for the motion detect area selected.
for i := Top to Bottom - 1 do
for j := Left to Right - 1 do
begin
iPixelPoint := (i * iQuadWidth * 2) + (j * 2);
//count maintains the count of no. of pixels
count := count + 1;
//brightness values of each pixel in current & previous image
liCurPx := ColorToRGB(pYuvBuf[iPixelPoint]); //current image
liKeyPx := ColorToRGB(asKeyBuf[ACameraNo][iPixelPoint]); //previous image
//sum of the colour values of each pixel in the current image
curBrightnessVal := curBrightnessVal + liCurPx;
//sum of the colour values of each pixel in the previous image
keyBrightnessVal := keyBrightnessVal + liKeyPx;
end;
//mean brightness of the current image
CurMeanBrightness := round((curBrightnessVal / count));
//mean brightness of the previous image
KeyMeanBrightness := round((keyBrightnessVal / count));
for i := Top to Bottom - 1 do
for j := Left to Right - 1 do
begin
iPixelPoint := (i * iQuadWidth * 2) + (j * 2);
if pYuvBuf[iPixelPoint] < 0 then
liCurPx := pYuvBuf[iPixelPoint] + 256
else liCurPx := pYuvBuf[iPixelPoint];
//mean brightness subtracted from each pixel in the current image
liCurPx := liCurPx - CurMeanBrightness;
if asKeyBuf[ACameraNo][iPixelPoint] < 0 then
liKeyPx := asKeyBuf[ACameraNo][iPixelPoint] + 256
else liKeyPx := asKeyBuf[ACameraNo][iPixelPoint];
//mean brightness subtracted from each pixel in the previous image
liKeyPx := liKeyPx - keyMeanBrightness;
liSum := liSum + ABS(liCurPx - liKeyPx);
end;
if ((Right - (Left - 1)) * (Bottom - (Top - 1))) = 0 then Continue;
liSum := liSum div ((Right - (Left - 1)) * (Bottom - (Top - 1)));
end;
if liSum > WorkConfig.Camera[ACameraNo].MotionSensitivity then
begin
Result := True;
Exit;
end;
end;
**************code snippet - End***************************
looking forward to your reply,
thanks & regards,
atul.
I tried computing the mean brightness and subtract it from each pixel. But i am unable to get the required results.
This code still considers the light flickering to be a motion and starts recording. I want to avoid this.
I am calculating the mean brightness of the current image and subtracting it from each pixel of the current image. same i do for the previous image. but i dont understand for the code to not work.
I am posting my source code in delphi for your reference. kindly take time to look into it and correct me if i am going wrong. I would be highly obliged if you put some time into this since its urgent to me.
below is my source code,
**************code snippet - Start***************************
//for no. of motion detect areas selected.
for iArea := 0 to MAX_MOTION_AREA - 1 do
begin
//variables initialised for each motion detect area
count := 0;
curBrightnessVal := 0;
keyBrightnessVal := 0;
CurMeanBrightness := 0;
KeyMeanBrightness := 0;
with WorkConfig.Camera[ACameraNo].MotionDetectArea[iArea] do
begin
//calculates the mean brightness for the motion detect area selected.
for i := Top to Bottom - 1 do
for j := Left to Right - 1 do
begin
iPixelPoint := (i * iQuadWidth * 2) + (j * 2);
//count maintains the count of no. of pixels
count := count + 1;
//brightness values of each pixel in current & previous image
liCurPx := ColorToRGB(pYuvBuf[iPixelPoint]); //current image
liKeyPx := ColorToRGB(asKeyBuf[ACameraNo][iPixelPoint]); //previous image
//sum of the colour values of each pixel in the current image
curBrightnessVal := curBrightnessVal + liCurPx;
//sum of the colour values of each pixel in the previous image
keyBrightnessVal := keyBrightnessVal + liKeyPx;
end;
//mean brightness of the current image
CurMeanBrightness := round((curBrightnessVal / count));
//mean brightness of the previous image
KeyMeanBrightness := round((keyBrightnessVal / count));
for i := Top to Bottom - 1 do
for j := Left to Right - 1 do
begin
iPixelPoint := (i * iQuadWidth * 2) + (j * 2);
if pYuvBuf[iPixelPoint] < 0 then
liCurPx := pYuvBuf[iPixelPoint] + 256
else liCurPx := pYuvBuf[iPixelPoint];
//mean brightness subtracted from each pixel in the current image
liCurPx := liCurPx - CurMeanBrightness;
if asKeyBuf[ACameraNo][iPixelPoint] < 0 then
liKeyPx := asKeyBuf[ACameraNo][iPixelPoint] + 256
else liKeyPx := asKeyBuf[ACameraNo][iPixelPoint];
//mean brightness subtracted from each pixel in the previous image
liKeyPx := liKeyPx - keyMeanBrightness;
liSum := liSum + ABS(liCurPx - liKeyPx);
end;
if ((Right - (Left - 1)) * (Bottom - (Top - 1))) = 0 then Continue;
liSum := liSum div ((Right - (Left - 1)) * (Bottom - (Top - 1)));
end;
if liSum > WorkConfig.Camera[ACameraNo].MotionSensitivity then
begin
Result := True;
Exit;
end;
end;
**************code snippet - End***************************
looking forward to your reply,
thanks & regards,
atul.