1

I am busy converting and interpreting software used in previous years of my final year project. I would just like to check if it is possible to define a background model in a header file, as i am currently getting an error.

class CWaterFill
{
public:
    void Initialise();
    Mat ContourFilter(Mat Img, int minSize);
    Mat superminImg;

protected:  
    BackgroundSubtractorMOG2 m_bg_model;//Define the background model.

};

enter image description here

It is then used in the .cpp file in the following function:

void CWaterFill::GMM2(Mat InputImg, int nFrame, double learnRate)
{
    m_bg_model(InputImg, m_fgmask, learnRate);//m_fgmask outlook is
}
James Mallett
  • 827
  • 4
  • 11
  • 27

1 Answers1

1

Use a pointer to an abstract BackgroundSubtractor object:

...
protected:  
    cv::Ptr<BackgroundSubtractor> m_bg_model;//Define the background model.

And then create the concrete type, e.g.:

m_bg_model = createBackgroundSubtractorMOG2(20, 16, true);
Miki
  • 40,887
  • 13
  • 123
  • 202
  • void CWaterFill::GMM2(Mat InputImg, int nFrame, double learnRate) { m_bg_model(InputImg, m_fgmask, learnRate);//m_fgmask is output } // If this is the only place that it is used, where would I add the concrete type definition? – James Mallett Sep 06 '16 at 09:33
  • @JamesMallett in the constructor of `CWaterFill` – Miki Sep 06 '16 at 11:39