在C#中提取两个图像之间的差异
我正在 C# 中使用网络摄像头(使用 AForge)。我也有一些默认背景。我需要提取当前图像和背景之间的差异,并创建一个新图像,其中仅包含默认背景上不存在的对象。例如,如果我将手移到网络摄像头前,我只需要输出那只手(其余背景为白色)。如果我只是逐个像素地比较,它会变得很难看,因为有很多噪音。我尝试过使用阈值进行差异,但结果仍然很糟糕。我认为也许有一些过滤器或已知的算法如何做到这一点?任何帮助将非常感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以尝试比较两者的灰度图像。假设您的网络摄像头是静止的(因为如果不是,那么您将不得不对像素移位进行更多调整),然后您可以将图像转换为灰度,并设置一个您认为图像不同的阈值:
阈值是如何您想要获得的像素之间有很大的容差。该值可以来自图像亮度的差异。
这样,您将不会获得最清晰的结果,因为您覆盖的某些像素将匹配,但是,您可以运行额外的扫描(如果您愿意),并进行某种区域填充。
You can always try to compare the grayscale images of the two. Assuming that your webcam is stationary (because if not, then you would have to do much more adjusting to pixel shifts), then you can convert the images to grayscale, and have a threshold by which you think the images differ:
The threshold is how much tolerance between the pixels you want to get. That value can come from the difference in brightness of the images.
With this you won't get the crispiest results, because some pixels you cover will match, however, you can then run an extra scan (if you want), and doing some kind of an area fill.