请看下面的代码
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
using namespace cv;
using namespace std;
Mat frame,back,fore;
int main()
{
VideoCapture cam;
BackgroundSubtractorMOG2 bgs(0,0,false);
vector<vector<Point>>contours;
bgs.setInt("nmixtures",3);
cam.open(0);
if(!cam.isOpened())
{
cout << "Cam not Found";
return -1;
}
namedWindow("Frame");
while(true)
{
cam>>frame;
imshow("Frame",frame);
if(waitKey(30)>=0)
{
break;
}
}
}
我正在尝试将 BackgroundSubtractorMOG2
的 nmixures
的值设置为 3,将 BackgroundSubtractorMOG2
的 bShadowDetection
的值设置为 假
。
但是,与 OpenCV 2.4.5 一样,这些值设置为私有(private),因此我无法直接访问它们。我设法通过构造函数设置了 bShadowDetection 的值(尽管我不知道其他 2 个参数是什么),但我找不到设置 nmixers 的方法。我不知道我设置nmixures的方式是否正确,因为在我读到的文章中,作者说“在opencv 2.4的情况下通过构造函数设置它们”
您能告诉我如何设置这两个值吗?
最佳答案
在 OpenCV 2.4.8 中:
bgs.set("nmixtures", 3);
bgs.set("detectShadows", false);
关于c++ - 如何在 'nmixures' 中设置 'bShadowDetection' 和 'BackgroundSubtractorMOG2' 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143781/