使用 OpenCV 进行高效背景扣除

发布于 2024-08-17 01:56:19 字数 544 浏览 10 评论 0原文

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

我可以使用掩蔽技术来做到这一点?? 就像我正在考虑的以下过程一样:

  1. 捕获输入 - InputFrame (RGB)
  2. Process InputFrame
  3. 减去背景,将前景存储在 TempFrame 中。 > (以灰度形式出现 :(
  4. 使用 TempFrame 创建蒙版
  5. 将创建的蒙版应用到 InputFrame
  6. 获取彩色前景作为 OutFrame

我对使用 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. 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

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

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不一样的天空 2024-08-24 01:56:19

http://vimeo.com/27477093

代码位于此处

http://code.google.com/p/derin-deli-mavi/downloads/detail?name=denemeOpenCv23.zip& ;can=2&q=

到达彩色前景
只需使用前景蒙版复制图像

// image.copyTo(foreground,foreground);

http://vimeo.com/27477093

code is here

http://code.google.com/p/derin-deli-mavi/downloads/detail?name=denemeOpenCv23.zip&can=2&q=

to reach a colored foreground
just copy image by using foreground mask

// image.copyTo(foreground,foreground);

妥活 2024-08-24 01:56:19

好吧,我不明白如果您使用背景减法,TempFrame(您的前景)怎么会是灰度的。你一定使用了一种非常特殊的算法。但假设 TempFrame 是灰度的,那么你会这样做:

cv::Mat mask = tempFrame > 0.5;

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

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

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);

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文