Ask Your Question

newbie123's profile - activity

2017-03-23 13:34:14 -0600 asked a question export Gaussian mixture model of backgroundsubtractorMOG2

I'm using the MOG2 algorithm for background subtration in opencv 3.2. I want to look at the learned gaussian mixture models(weights, variance, mean...), however opencv does not provide built-in function to look at the values.

In bgfg_gaussmix2.cpp source code, I found the variables I need in class BackgroundSubtractorMOG2Impl:

  UMat u_weight;
  UMat u_variance;
  UMat u_mean;
  UMat u_bgmodelUsedMod

So what I did is just put some functions that can return the variables(in the same format as the built-in functions)

 virtual UMat getWeight() const { return u_weight; }
 virtual UMat getVariance() const { return u_variance; }
 virtual UMat getMean() const { return u_mean; }
 virtual UMat getNmodes() const {return u_bgmodelUsedModes;}

Then I also added the following to the background_segm.hpp file, in class CV_EXPORTS_W BackgroundSubtractorMOG2:

CV_WRAP virtual UMat getWeight() const = 0;
CV_WRAP virtual UMat getVariance() const = 0;
CV_WRAP virtual UMat getMean() const = 0;
CV_WRAP virtual UMat getNmodes() const = 0;

After this, I build and install the modified opencv source code. Then I wrote my own program to run the backgroundubtractorMOG2 algorithm. I can call the new functions I added to the opencv source code to return those UMat, but the returned UMats are just full of zeros.

So my question is how to get the UMats in the right way?