Ask Your Question

Aravind Nambissan's profile - activity

2020-11-28 03:36:20 -0600 received badge  Good Question (source)
2016-12-29 04:31:24 -0600 received badge  Popular Question (source)
2014-06-17 04:47:14 -0600 received badge  Nice Question (source)
2013-03-01 20:20:26 -0600 received badge  Student (source)
2012-12-13 11:14:15 -0600 asked a question In BackgroundSubtractorMOG2 set background fixed(static) like BackgroundSubtractorMOG

Is there any way to fix the background set in BackgroundSubtractorMOG2 as in BackgroundSubtractorMOG.

heres my code to detect hand ... It does not have a fixed background

    #include<opencv2/opencv.hpp>
    #include<iostream>
    #include<vector> 
    using namespace cv; 
    using namespace std;

    const int nmixtures=10; 
    const bool shadow=false;  
    const int history =1000;

    BackgroundSubtractorMOG2 back_obj(history,nmixtures,shadow); 
    //BackgroundSubtractorMOG back_obj;  this gives me a first frame as fixed background. 
    int main(int argc,char **argv) { 

     Mat original; 
     Mat background,foreground; 
     VideoCapture cap(0); 
     std::vector<std::vector<cv::Point> >contours; 
     namedWindow("ORIGINAL"); 
     namedWindow("BACKGROUND"); 
     namedWindow("FOREGROUND"); 
     while(1)
     {
            cap>>original;  
            back_obj.operator()(original,foreground);
            back_obj.getBackgroundImage(background);    
            erode(foreground,foreground,Mat());         
            dilate(foreground,foreground,Mat());                         
            findContours(foreground,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);      
            drawContours(original,contours,-1,Scalar(255,255,0),4);     
            imshow("ORIGINAL",original);    
            imshow("BACKGROUND",background);
            imshow("FOREGROUND",foreground);    
            if(waitKey(10)>=0) 
            {
           break;
          }
     }
     return 0;
    }