Ale*_*xey 7 c++ opencv background-subtraction
OpenCV库版本2.42.我想在BackgroundSubtractorMOG2对象中设置一个参数,例如
BackgroundSubtractorMOG2 bgr;
// the following doesn't work because 'nmixtures', 'backgroundRatio'
// and 'fVarMin' are a protected members.
bgr.nmixtures = 3;
bgr.backgroundRatio = 0.9;
bgr.fVarMin = 5;
// the following works
bgr.set('nmixtures', 3);
// both of the following lines will give a run-time error
// `Access violation reading location 0x0000000000000008.`
bgr.set("backgroundRatio", 0.9);
bgr.set("fVarMin", 5);
Run Code Online (Sandbox Code Playgroud)
backgroundRatio并且fVarMin是控制算法的参数.用户应该能够根据文档更改这些参数.
我该如何设置参数BackgroundSubtractorMOG2?
编辑正如下面的答案中正确提到的,这是OpenCV中的一个错误.该错误已在OpenCV版本2.4.6中修复.
我刚刚查看了OpenCV源代码,发现文件中有趣的初始化/modules/video/src/video_init.cpp.这里是:
CV_INIT_ALGORITHM(BackgroundSubtractorMOG2, "BackgroundSubtractor.MOG2",
obj.info()->addParam(obj, "history", obj.history);
obj.info()->addParam(obj, "nmixtures", obj.nmixtures);
obj.info()->addParam(obj, "varThreshold", obj.varThreshold);
obj.info()->addParam(obj, "detectShadows", obj.bShadowDetection));
Run Code Online (Sandbox Code Playgroud)
似乎可以使用方法仅设置这四个参数set.
还要看看modules/video/src/bgfg_gaussmix2.cpp有一个BackgroundSubtractorMOG2类的文件.它有以下字段:
float fVarInit;
float fVarMax;
float fVarMin;
//initial standard deviation for the newly generated components.
//It will will influence the speed of adaptation. A good guess should be made.
//A simple way is to estimate the typical standard deviation from the images.
//I used here 10 as a reasonable value
Run Code Online (Sandbox Code Playgroud)
并且值fVarMin(您想要更改)设置为:
fVarMin = defaultVarMin2
Run Code Online (Sandbox Code Playgroud)
在两个构造函数中.以下是所有这些:
static const float defaultVarInit2 = 15.0f; // initial variance for new components
static const float defaultVarMax2 = 5*defaultVarInit2;
static const float defaultVarMin2 = 4.0f;
Run Code Online (Sandbox Code Playgroud)
有趣的是,这个值没有在任何其他文件中使用,所以现在似乎无法改变它.您可以将此问题直接发布到OpenCV bugtracker.
| 归档时间: |
|
| 查看次数: |
10155 次 |
| 最近记录: |