c – 无法在BackgroundSubtractorMOG2中设置用户参数

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

backgroundratio和fVarMin是控制算法的参数.用户应该能够根据documentation更改这些参数.

如何设置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));

似乎可以使用方法集仅设置这四个参数.

还要看一下文件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

并且值fVarMin(您想要更改)设置为:

fVarMin = defaultvarMin2

在两个构造函数中.以下是所有这些:

static const float defaultvarInit2 = 15.0f; // initial variance for new components
static const float defaultvarMax2 = 5*defaultvarInit2;
static const float defaultvarMin2 = 4.0f;

有趣的是,这个值没有在任何其他文件中使用,所以现在似乎无法改变它.您可以将此问题直接发布到OpenCV bugtracker.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...