使用OpenCV进行有效的背景扣除 [英] Efficient Background subtraction with OpenCV

查看:111
本文介绍了使用OpenCV进行有效的背景扣除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OpenCV方法在视频文件中进行背景减法.现在,我可以进行背景扣除,但是问题是我无法在彩色模式下获得输出.减去背景后的所有输出均以灰度颜色模式:(.我想将颜色信息显示为前景,这是减去背景后得到的输出.

I want to do background subtraction in a video file using OpenCV method. Right now I'm able to do background subtraction, but the problem is that I couldn't get the output in color mode. All the output after subtracting the background is coming in grayscale color mode :(. I want to get the color information to the foreground which is the resulting output after background got subtracted.

我可以使用遮罩技术吗?就像我正在考虑的以下过程.

Can I do it using masking technique?? like the following procedure which I'm thinking about.

  1. 捕获输入-InputFrame(RGB)
  2. 处理InputFrame
  3. 减去背景,将前景存储在TempFrame中(以灰度级显示:()
  4. 使用TempFrame
  5. 创建蒙版
  6. 将创建的遮罩应用于InputFrame
  7. 将彩色前景作为OutFrame
  1. Capture Input -- InputFrame (RGB)
  2. Process InputFrame
  3. Subtract background, store foreground in TempFrame (which is coming in grayscale :( )
  4. Create a mask using TempFrame
  5. Apply the created mask to the InputFrame
  6. Get colored foreground as OutFrame

我对使用OpenCV进行掩膜感到震惊.我只是OpenCV的初学者.请帮助我克服这个问题.

I'm struck up with doing the masking using OpenCV. I'm just a very beginner in OpenCV. Please help me to overcome this.

谢谢.

推荐答案

好吧,如果您使用背景减法,我不明白如何将TempFrame(您的前景)设为灰度.您必须使用非常特殊的算法.但是假设TempFrame是灰度的,那么您可以这样做:

Okay, I don't understand how TempFrame (your foreground) could be greyscale if you are using background subtraction. You must be using a very special algorithm. But assuming TempFrame is greyscale, then you would do this:

cv::Mat mask = tempFrame > 0.5;

cv::Mat outFrame;
capturedFrame.copyTo(outFrame, mask);

那是上面的OpenCV 2.0代码.数字0.5是一个阈值,您需要将其设置为适当的值.如果您不使用浮点图像,则可以将其设置为128或类似的值.这与OpenCV 1.1代码相同:

That is OpenCV 2.0 code above. The number 0.5 is a threshold, you'll need to set it to something appropriate. If you're not using floating-point images, you'd probably set it to 128 or something like that. This is the same thing in OpenCV 1.1 code:

CvMat* mask = cvCreateMat(tempFrame.rows, tempFrame.cols, CV_8UC1);
cvCmpS(tempFrame, 0.5, mask);

CvMat* outFrame = cvCreateMat(capturedFrame.rows, capturedFrames.cols, CV_32FC3);
cvCopy(capturedFrame, outFrame, mask);

这篇关于使用OpenCV进行有效的背景扣除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆