Error in BackgroundSubtraction Mog2

I use opencv 2.4.4, and when I run this algorithm on it, it gives me an 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's

 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 as shown below, it does not give a syntax error, but gives me an error at runtime

 bg.set("nmixtures", 3); bg.set("detectShadows", false); 

Error

 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 

thanks

+4
source share
3 answers

Your displayed error says (no parameter nmixture is found) . The problem here is that you typed nmixture instead of nmixtures .

Shadow detection cannot be set using the .set() function; This is a bug in opencv. If you want to install it, you must initialize it in your constructor . Here's 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 
+3
source

It was a mistake: http://code.opencv.org/issues/2168

The bug has been fixed, and the fix will be available in version 2.4.6 (it is already available in the 2.4 branch).

UPDATE

In your case use

 bg.set("nmixtures", 3); bg.set("detectShadows", false); 

Regarding the linker error:

 error LNK2019: unresolved external symbol ... 

Perhaps you forgot to associate with opencv_video244.lib?

+1
source

OpenCV 2.4. nmixtures are protected, not public, so you may need to set the values ​​for nmixtures and bShadowDetection using the constructor

-1
source

Source: https://habr.com/ru/post/976544/


All Articles