OpenCV 背景减法 c++

OpenCV Background Substraction c++

我已经创建了一个背景减法器 (MOG),现在我想更改一些参数:

Ptr< BackgroundSubtractor> pMOG, pMOG2;
pMOG = new BackgroundSubtractorMOG();
pMOG.set("varThreshold",5); //does't work
pMOG->operator()(inputImage, outputImage); //works, but the output is not enought "sensitive"

有人知道我该如何处理吗?我想更改阈值,因为它 returns 是一个遮罩,并不总是检测到我移动的物体(例如,如果它们的颜色接近背景颜色)。

谢谢!

那是因为 BackgroundSubtractorMOG 没有名为 varThreshold 的参数。您可能想在 BackgroundSubtractorMOG2.

上设置此参数

BackgroundSubtractorMOG的参数是:

"history"
"nmixtures"
"backgroundRatio"
"noiseSigma"

BackgroundSubtractorMOG2 是:

"history"
"nmixtures"
"varThreshold"
"detectShadows"
"backgroundRatio"
"varThresholdGen"
"fVarInit"
"fVarMin"
"fVarMax"
"fCT"
"nShadowDetection"
"fTau"

您可以在 video_init.cpp 中找到这些信息(针对 OpenCV 版本 2.4.9 进行了检查)。


你也可以直接在构造函数中设置一些参数,这可能是最安全的方式。