36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
41 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
44 double backgroundRatio = 0.7;
45 double noiseSigma = 0;
46 for (
int i=2; i<nrhs; i+=2) {
47 string key(rhs[i].toString());
49 history = rhs[i+1].toInt();
50 else if (key ==
"NMixtures")
51 nmixtures = rhs[i+1].toInt();
52 else if (key ==
"BackgroundRatio")
53 backgroundRatio = rhs[i+1].toDouble();
54 else if (key ==
"NoiseSigma")
55 noiseSigma = rhs[i+1].toDouble();
58 "Unrecognized option %s", key.
c_str());
61 history, nmixtures, backgroundRatio, noiseSigma);
71 if (method ==
"delete") {
76 else if (method ==
"clear") {
80 else if (method ==
"save") {
82 obj->
save(rhs[2].toString());
84 else if (method ==
"load") {
85 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
87 bool loadFromString =
false;
88 for (
int i=3; i<nrhs; i+=2) {
89 string key(rhs[i].toString());
91 objname = rhs[i+1].toString();
92 else if (key ==
"FromString")
93 loadFromString = rhs[i+1].toBool();
96 "Unrecognized option %s", key.
c_str());
105 FileStorage fs(rhs[2].toString(), FileStorage::READ +
106 (loadFromString ? FileStorage::MEMORY : 0));
115 else if (method ==
"empty") {
119 else if (method ==
"getDefaultName") {
123 else if (method ==
"apply") {
124 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
125 double learningRate = -1;
126 for (
int i=3; i<nrhs; i+=2) {
127 string key(rhs[i].toString());
128 if (key ==
"LearningRate")
129 learningRate = rhs[i+1].toDouble();
132 "Unrecognized option %s", key.
c_str());
135 obj->
apply(image, fgmask, learningRate);
138 else if (method ==
"getBackgroundImage") {
142 plhs[0] =
MxArray(backgroundImage);
144 else if (method ==
"get") {
146 string prop(rhs[2].toString());
147 if (prop ==
"History")
149 else if (prop ==
"NMixtures")
151 else if (prop ==
"BackgroundRatio")
153 else if (prop ==
"NoiseSigma")
157 "Unrecognized property %s", prop.
c_str());
159 else if (method ==
"set") {
161 string prop(rhs[2].toString());
162 if (prop ==
"History")
164 else if (prop ==
"NMixtures")
166 else if (prop ==
"BackgroundRatio")
168 else if (prop ==
"NoiseSigma")
172 "Unrecognized property %s", prop.
c_str());
176 "Unrecognized operation %s", method.
c_str());
virtual void setNMixtures(int nmix)=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual int getHistory() const=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
Ptr< cuda::BackgroundSubtractorMOG > createBackgroundSubtractorMOG(int history=200, int nmixtures=5, double backgroundRatio=0.7, double noiseSigma=0)
virtual void setNoiseSigma(double noiseSigma)=0
virtual double getBackgroundRatio() const=0
virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1)=0
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual double getNoiseSigma() const=0
virtual void getBackgroundImage(OutputArray backgroundImage) const=0
virtual void read(const FileNode &fn)
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
FileNode getFirstTopLevelNode() const
virtual void setBackgroundRatio(double backgroundRatio)=0
virtual String getDefaultName() const
Global constant definitions.
int last_id
Last object id to allocate.
virtual int getNMixtures() const=0
virtual void save(const String &filename) const
virtual bool empty() const
virtual void setHistory(int nframes)=0
map< int, Ptr< BackgroundSubtractorMOG > > obj_
Object container.