简体   繁体   English

使用Emgu cv进行后台替换

[英]Background Subtaction using Emgu cv

I need to know that is there a method to remove the background of a live streaming web cam. 我需要知道有没有一种方法可以删除实时流网络摄像头的背景。 There is a method called background Subtractor . 有一种称为背景减法器的方法。 If anyone knows to use that please help me out with the issue.. 如果有人知道用那个,请帮我解决这个问题。

If you already have an image of the background you can just calculate 如果您已经有背景图片,则可以计算

I - B

Where I is the Image and B is the background (of type say, Image) 其中我是图片,背景是B(类型为图片)

B - I B-我

Will also work. 也可以。

Since images don't store negative numbers, you may wish to combine these both using 由于图像不存储负数,因此您可能希望使用

(I - B) + (B - I) (我-B)+(我-B)

And convert the result to grayscale. 并将结果转换为灰度。

I method which I have found works better is to do this using fourier transforms. 我发现更好的方法是使用傅立叶变换。

ie: 即:

F^-1(F(I) - F(B)) F ^ -1(F(I)-F(B))

for example 例如

    CvInvoke.cvDFT(video.Convert<Gray, Single>().Ptr, DFT.Ptr, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, -1);
    CvInvoke.cvDFT(Background.Convert<Gray, Single>().Ptr, DFTBack.Ptr, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, -1);

    CvInvoke.cvDFT((DFTBack - DFT).Convert<Gray, Single>().Ptr, originalLeft.Ptr, Emgu.CV.CvEnum.CV_DXT.CV_DXT_INVERSE, -1);
    CvInvoke.cvDFT((DFT - DFTBack).Ptr, originalRight.Ptr, Emgu.CV.CvEnum.CV_DXT.CV_DXT_INVERSE, -1);

This works well when the foreground is partially translucent. 当前景部分透明时,此方法效果很好。

There's also the built in Foreground detector 还有内置的前景探测器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM