Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

BackgroundSubtractorMOG2 in OpenCV 3.4.1

I am working on existing project which was written in VisualStudio 2012 (C++) and OpenCV 2.4.9. Now I am rewriting it to Studio 2017 and OpenCV 3.4.1. I have the problem with class BackgroundSubtractorMOG2. In previous version of OpenCV this class was not abstract and has several member variables declared in header file. In version 3.4.1 it is abstract class and has only pure virtual methods. There exists a derived class in our project class MotionEstimator:public BackgroundSubtractorMOG2 { cv::Mat bgmask; public: MotionEstimator(); virtual void SetReference(cv::Mat &frame); Mat process(cv::Mat &frame,vector<rect> objects); void bkgdetect(cv::InputArray image, cv::OutputArray fgmask, cv::Mat mask,double learningRateBG=-1,double learningRateFG=-1); int width,height; };

and it cannot be compiled, because the instance of abstract class cannot be created. I tried to rewrite this code such way : class MotionEstimator { cv::Ptr<cv::backgroundsubtractormog2> pBase; cv::Mat bgmask; public: ..... };

but there is another problem in internal methods process and bkgdetect. These methods use several member variables from old version of BackgroundSubtractorMOG2 which are not present in version 3.4.1. So it cannot be compiled again.

Old version of BackgroundSubtractorMOG2: class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor { public: //! the default constructor CV_WRAP BackgroundSubtractorMOG2(); //! the full constructor that takes the length of the history, the number of gaussian mixtures, the background ratio parameter and the noise strength CV_WRAP BackgroundSubtractorMOG2(int history, float varThreshold, bool bShadowDetection=true); //! the destructor .....

protected: Size frameSize; int frameType; Mat bgmodel; Mat bgmodelUsedModes;//keep track of number of modes per pixel int nframes; int history; int nmixtures; .....

New version: class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor { public: /* @brief Returns the number of last frames that affect the background model */ CV_WRAP virtual int getHistory() const = 0; /* @brief Sets the number of last frames that affect the background model */ CV_WRAP virtual void setHistory(int history) = 0;

/** @brief Returns the number of gaussian components in the background model
*/
CV_WRAP virtual int getNMixtures() const = 0;
...... and many other pure virtual methods ........

Have you any idea how to rewrite the code to new OpenCV 3.4.1.?

BackgroundSubtractorMOG2 in OpenCV 3.4.1

I am working on existing project which was written in VisualStudio 2012 (C++) and OpenCV 2.4.9. Now I am rewriting it to Studio 2017 and OpenCV 3.4.1. I have the problem with class BackgroundSubtractorMOG2. In previous version of OpenCV this class was not abstract and has several member variables declared in header file. In version 3.4.1 it is abstract class and has only pure virtual methods. There exists a derived class in our project class MotionEstimator:public BackgroundSubtractorMOG2 BackgroundSubtractorMOG2

{
    cv::Mat bgmask;
public:
    MotionEstimator();
    virtual void SetReference(cv::Mat &frame);
    Mat process(cv::Mat &frame,vector<rect> &frame,vector<Rect> objects);
    void bkgdetect(cv::InputArray image, cv::OutputArray fgmask, cv::Mat mask,double learningRateBG=-1,double learningRateFG=-1);
    int width,height;
};

};

and it cannot be compiled, because the instance of abstract class cannot be created. I tried to rewrite this code such way : :

class MotionEstimator
{
    cv::Ptr<cv::backgroundsubtractormog2> cv::Ptr<cv::BackgroundSubtractorMOG2> pBase;
    cv::Mat bgmask;
public:
    .....
};

};

but there is another problem in internal methods process and bkgdetect. These methods use several member variables from old version of BackgroundSubtractorMOG2 which are not present in version 3.4.1. So it cannot be compiled again.

Old version of BackgroundSubtractorMOG2: BackgroundSubtractorMOG2:

class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
{
public:
    //! the default constructor
    CV_WRAP BackgroundSubtractorMOG2();
    //! the full constructor that takes the length of the history, the number of gaussian mixtures, the background ratio parameter and the noise strength
    CV_WRAP BackgroundSubtractorMOG2(int history,  float varThreshold, bool bShadowDetection=true);
    //! the destructor
    .....

..... protected: Size frameSize; int frameType; Mat bgmodel; Mat bgmodelUsedModes;//keep track of number of modes per pixel int nframes; int history; int nmixtures; .....

.....

New version: version:

class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
{
public:
    /* /** @brief Returns the number of last frames that affect the background model
    */
    CV_WRAP virtual int getHistory() const = 0;
    /* /** @brief Sets the number of last frames that affect the background model
    */
    CV_WRAP virtual void setHistory(int history) = 0;

0;

    /** @brief Returns the number of gaussian components in the background model
 */
 CV_WRAP virtual int getNMixtures() const = 0;
 ...... and many other pure virtual methods ........

Have you any idea how to rewrite the code to new OpenCV 3.4.1.?

3.4.1.?

BackgroundSubtractorMOG2 in OpenCV 3.4.1

I am working on existing project which was written in VisualStudio 2012 (C++) and OpenCV 2.4.9. Now I am rewriting it to Studio 2017 and OpenCV 3.4.1. I have the problem with class BackgroundSubtractorMOG2. In previous version of OpenCV this class was not abstract and has several member variables declared in header file. In version 3.4.1 it is abstract class and has only pure virtual methods. There exists a derived class in our project class MotionEstimator:public BackgroundSubtractorMOG2project

class MotionEstimator:public BackgroundSubtractorMOG2

{
    cv::Mat bgmask;
public:
    MotionEstimator();
    virtual void SetReference(cv::Mat &frame);
    Mat process(cv::Mat &frame,vector<Rect> objects);
    void bkgdetect(cv::InputArray image, cv::OutputArray fgmask, cv::Mat mask,double learningRateBG=-1,double learningRateFG=-1);
    int width,height;
};

and it cannot be compiled, because the instance of abstract class cannot be created. I tried to rewrite this code such way :

class MotionEstimator
{
    cv::Ptr<cv::BackgroundSubtractorMOG2> pBase;
    cv::Mat bgmask;
public:
    .....
};

but there is another problem in internal methods process and bkgdetect. These methods use several member variables from old version of BackgroundSubtractorMOG2 which are not present in version 3.4.1. So it cannot be compiled again.

Old version of BackgroundSubtractorMOG2:

class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
{
public:
    //! the default constructor
    CV_WRAP BackgroundSubtractorMOG2();
    //! the full constructor that takes the length of the history, the number of gaussian mixtures, the background ratio parameter and the noise strength
    CV_WRAP BackgroundSubtractorMOG2(int history,  float varThreshold, bool bShadowDetection=true);
    //! the destructor
    .....

protected:
    Size frameSize;
    int frameType;
    Mat bgmodel;
    Mat bgmodelUsedModes;//keep track of number of modes per pixel
    int nframes;
    int history;
    int nmixtures;
    .....

New version:

class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
{
public:
    /** @brief Returns the number of last frames that affect the background model
    */
    CV_WRAP virtual int getHistory() const = 0;
    /** @brief Sets the number of last frames that affect the background model
    */
    CV_WRAP virtual void setHistory(int history) = 0;

    /** @brief Returns the number of gaussian components in the background model
    */
    CV_WRAP virtual int getNMixtures() const = 0;
    ...... and many other pure virtual methods ........

Have you any idea how to rewrite the code to new OpenCV 3.4.1.?

BackgroundSubtractorMOG2 in OpenCV 3.4.1

I am working on existing project which was written in VisualStudio 2012 (C++) and OpenCV 2.4.9. Now I am rewriting it to Studio 2017 and OpenCV 3.4.1. I have the problem with class BackgroundSubtractorMOG2. In previous version of OpenCV this class was not abstract and has several member variables declared in header file. In version 3.4.1 it is abstract class and has only pure virtual methods. There exists a derived class in our project

class MotionEstimator:public BackgroundSubtractorMOG2

{
    cv::Mat bgmask;
public:
    MotionEstimator();
    virtual void SetReference(cv::Mat &frame);
    Mat process(cv::Mat &frame,vector<Rect> objects);
    void bkgdetect(cv::InputArray image, cv::OutputArray fgmask, cv::Mat mask,double learningRateBG=-1,double learningRateFG=-1);
    int width,height;
};

and it cannot be compiled, because the instance of abstract class cannot be created. I tried to rewrite this code such way :

class MotionEstimator
{
    cv::Ptr<cv::BackgroundSubtractorMOG2> pBase;
    cv::Mat bgmask;
public:
    .....
};

but there is another problem in internal methods process and bkgdetect. These methods use several member variables from old version of BackgroundSubtractorMOG2 which are not present in version 3.4.1. So it cannot be compiled again.

Old version of BackgroundSubtractorMOG2:

class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
{
public:
    //! the default constructor
    CV_WRAP BackgroundSubtractorMOG2();
    //! the full constructor that takes the length of the history, the number of gaussian mixtures, the background ratio parameter and the noise strength
    CV_WRAP BackgroundSubtractorMOG2(int history,  float varThreshold, bool bShadowDetection=true);
    //! the destructor
    .....

protected:
    Size frameSize;
    int frameType;
    Mat bgmodel;
    Mat bgmodelUsedModes;//keep track of number of modes per pixel
    int nframes;
    int history;
    int nmixtures;
    .....

New version:

class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
{
public:
    /** @brief Returns the number of last frames that affect the background model
    */
    CV_WRAP virtual int getHistory() const = 0;
    /** @brief Sets the number of last frames that affect the background model
    */
    CV_WRAP virtual void setHistory(int history) = 0;

    /** @brief Returns the number of gaussian components in the background model
    */
    CV_WRAP virtual int getNMixtures() const = 0;
    ...... and many other pure virtual methods ........
 

Have you any idea how to rewrite the code to new OpenCV 3.4.1.? 3.4.1.?