3

I am using webcamera in C# (using AForge). I also have some default background. I need to extract the difference between current image and background and create a new image which contains only the objects which are not present on the default background. For example, if I move my hand in front of webcamera, I need to output only that hand (with the rest of backgound white). If I just compare pixel by pixel it gets ugly, since there is a lot of noise. I have tried using threshold value for difference, but the result is still very bad. I think that maybe there is some filter or a known algorithm how to do that? Any help would be very much appreciated.

4

1 回答 1

0

您可以随时尝试比较两者的灰度图像。假设您的网络摄像头是静止的(因为如果不是,那么您将不得不对像素偏移进行更多调整),那么您可以将图像转换为灰度,并设置一个您认为图像不同的阈值:

int threshold = 30;
PixAvg1[i,j] = (Pix1.R + Pix1.G + Pix1.B)/3
PixAvg2[i,j] = (Pix2.R + Pix2.G + Pix2.B)/3
if (Math.Abs(PixAvg1[i,j] - PixAvg2[i,j+1])>threshold)
    difPixel == true;

阈值是您想要获得的像素之间的公差。该值可能来自图像亮度的差异。

这样您将不会得到最清晰的结果,因为您覆盖的某些像素会匹配,但是,您可以运行额外的扫描(如果需要),并进行某种区域填充。

于 2013-06-26T15:32:38.597 回答