BackgroundSubtraction Mog2中出现错误 [英] Error in BackgroundSubtraction Mog2
问题描述
我使用opencv 2.4.4,当我运行这个算法,它给我的错误在 nmixtures
和 bShadowDetection
I am using opencv 2.4.4 and when i run this algorithm on it , it give me the error on nmixtures
and bShadowDetection
#include <iostream>
#include <sys/stat.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <opencv/cv.h>
#include "opencv2/features2d/features2d.hpp"
#include <opencv/highgui.h>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <vector>
#pragma comment (lib , "opencv_core244d.lib")
#pragma comment (lib ,"opencv_highgui244d.lib")
#pragma comment(lib , "opencv_imgproc244d.lib")
#pragma comment(lib ,"opencv_video244.lib")
using namespace cv;
int main(int argc, char *argv[])
{
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
cv::VideoCapture cap("try2.avi");
cap >> frame;
cv::initModule_video();
cv::BackgroundSubtractorMOG2 bg(100, 16, true); // history is an int, distance_threshold is an int (usually set to 16), shadow_detection is a bool
bg.set("nmixtures", 3);
bg(frame, fore, -1); //learning_rate = -1 here
std::vector<std::vector<cv::Point> > contours;
cv::namedWindow("Frame");
cv::namedWindow("Background");
for(;;)
{
cap >> frame;
bg.operator ()(frame,fore);
bg.getBackgroundImage(back);
cv::erode(fore,fore,cv::Mat());
cv::dilate(fore,fore,cv::Mat());
cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
cv::imshow("Frame",frame);
cv::imshow("Background",back);
if(cv::waitKey(30) >= 0) break;
}
return 0;
}
错误
error C2248: 'cv::BackgroundSubtractorMOG2::nmixtures' : cannot access protected member declared in class 'cv::BackgroundSubtractorMOG2'
error C2248: 'cv::BackgroundSubtractorMOG2::bShadowDetection' : cannot access protected member declared in class 'cv::BackgroundSubtractorMOG2'
,它没有给出语法错误,但在运行时给我错误。
When i use it like below , it didn't give syntax error , but give me error at runtime
bg.set("nmixtures", 3);
bg.set("detectShadows", false);
错误
Unhandled exception at 0x7617812f in WK01.exe: Microsoft C++ exception: cv::Exception at memory location 0x001de2d0..
opencv error : Bad argument (no parameter nmixture is found) in unknown function
感谢
推荐答案
您显示的错误说明(没有找到参数nmixture)
。这里的问题是,您键入 nmixture
而不是 nmixtures
。
Your displayed error says (no parameter nmixture is found)
. The issue here is that you've typed nmixture
instead of nmixtures
.
阴影检测不能使用 .set()
函数设置;这是opencv中的一个错误。如果您要设置,请在你的构造函数中初始化它。以下是初始化背景模型的方法:
Shadow detection cannot be set using the .set()
function; this is a bug in opencv. If you'd like to set it, you should initialize it in your constructor. Here is how you should initialize your background model:
cv::BackgroundSubtractorMOG2 bg(history, distance_threshold, shadow_detection); // history is an int, distance_threshold is an int (usually set to 16), shadow_detection is a bool
这篇关于BackgroundSubtraction Mog2中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!