从视频中提取背景场景

时间:2013-01-30 15:33:02

标签: c++ opencv qt-creator

我正在使用Qt和opencv开发视频处理项目。作为处理步骤,我需要从人类经过的视频(实时流)中提取背景。我需要知道Opencv是否具有用于从视频中提取静态对象的内置函数 ?

2 个答案:

答案 0 :(得分:3)

查看this OpenCV class

cv::Mat original;     // your frame
cv::Mat foreground;   // your foreground
cv::Mat background;   // your background

cv::BackgroundSubtractorMOG2 mog;

mog.history = 150;            // How many frames should be used for calculation
mog.nShadowDetection = false; // There are a lot of parameters to adjust

mog(original,foreground,0.01);  // Binary foreground saved in "foreground"

mog.getBackgroundImage(background); // Output the current background of the model

该类实现了高斯混合模型背景减法:

Z.Zivkovic,改进的自适应Gausian混合模型的背景    减法,国际会议模式识别,英国,    2004年8月,    http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf。代码是    非常快,并执行阴影检测。高斯数    组件按像素进行调整。

答案 1 :(得分:0)

最快的方法和简单的方法是使用前一帧的中位数

您可以使用第一个背景图像的更新过程来考虑新的静态对象 更复杂的方法,如Pinciple组件分析 - 高斯混合 - 自组织背景减法和CNN可以解决您的问题但不适合流式传输,除非您使用特殊硬件FPGA或GPU