35 int id = rhs[0].toInt();
36 string method(rhs[1].toString());
39 if (method ==
"new") {
40 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
42 double varThreshold = 16;
43 bool detectShadows =
true;
44 for (
int i=2; i<nrhs; i+=2) {
45 string key(rhs[i].toString());
47 history = rhs[i+1].toInt();
48 else if (key ==
"VarThreshold")
49 varThreshold = rhs[i+1].toDouble();
50 else if (key ==
"DetectShadows")
51 detectShadows = rhs[i+1].toBool();
54 "Unrecognized option %s", key.
c_str());
57 history, varThreshold, detectShadows);
67 if (method ==
"delete") {
72 else if (method ==
"clear") {
76 else if (method ==
"save") {
78 obj->
save(rhs[2].toString());
80 else if (method ==
"load") {
81 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
83 bool loadFromString =
false;
84 for (
int i=3; i<nrhs; i+=2) {
85 string key(rhs[i].toString());
87 objname = rhs[i+1].toString();
88 else if (key ==
"FromString")
89 loadFromString = rhs[i+1].toBool();
92 "Unrecognized option %s", key.
c_str());
101 FileStorage fs(rhs[2].toString(), FileStorage::READ +
102 (loadFromString ? FileStorage::MEMORY : 0));
111 else if (method ==
"empty") {
115 else if (method ==
"getDefaultName") {
119 else if (method ==
"apply") {
120 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
121 double learningRate = -1;
122 for (
int i=3; i<nrhs; i+=2) {
123 string key(rhs[i].toString());
124 if (key ==
"LearningRate")
125 learningRate = rhs[i+1].toDouble();
128 "Unrecognized option %s", key.
c_str());
131 obj->
apply(image, fgmask, learningRate);
134 else if (method ==
"getBackgroundImage") {
138 plhs[0] =
MxArray(backgroundImage);
140 else if (method ==
"get") {
142 string prop(rhs[2].toString());
143 if (prop ==
"History")
145 else if (prop ==
"NMixtures")
147 else if (prop ==
"BackgroundRatio")
149 else if (prop ==
"VarThreshold")
151 else if (prop ==
"VarThresholdGen")
153 else if (prop ==
"VarInit")
155 else if (prop ==
"VarMin")
157 else if (prop ==
"VarMax")
159 else if (prop ==
"ComplexityReductionThreshold")
161 else if (prop ==
"DetectShadows")
163 else if (prop ==
"ShadowValue")
165 else if (prop ==
"ShadowThreshold")
169 "Unrecognized property %s", prop.
c_str());
171 else if (method ==
"set") {
173 string prop(rhs[2].toString());
174 if (prop ==
"History")
176 else if (prop ==
"NMixtures")
178 else if (prop ==
"BackgroundRatio")
180 else if (prop ==
"VarThreshold")
182 else if (prop ==
"VarThresholdGen")
184 else if (prop ==
"VarInit")
186 else if (prop ==
"VarMin")
188 else if (prop ==
"VarMax")
190 else if (prop ==
"ComplexityReductionThreshold")
192 else if (prop ==
"DetectShadows")
194 else if (prop ==
"ShadowValue")
196 else if (prop ==
"ShadowThreshold")
200 "Unrecognized property %s", prop.
c_str());
204 "Unrecognized operation %s", method.
c_str());
virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1)=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual void setVarInit(double varInit)=0
virtual int getHistory() const=0
virtual void setNMixtures(int nmixtures)=0
virtual void setComplexityReductionThreshold(double ct)=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual void setHistory(int history)=0
virtual bool getDetectShadows() const=0
virtual int getShadowValue() const=0
virtual double getVarMin() const=0
virtual void setVarThresholdGen(double varThresholdGen)=0
virtual bool isOpened() const
virtual void setVarThreshold(double varThreshold)=0
virtual double getVarInit() const=0
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual void getBackgroundImage(OutputArray backgroundImage) const=0
virtual int getNMixtures() const=0
int last_id
Last object id to allocate.
virtual void read(const FileNode &fn)
virtual void setShadowThreshold(double threshold)=0
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...
virtual double getComplexityReductionThreshold() const=0
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
map< int, Ptr< BackgroundSubtractorMOG2 > > obj_
Object container.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
FileNode getFirstTopLevelNode() const
virtual String getDefaultName() const
Global constant definitions.
virtual double getVarMax() const=0
virtual double getVarThresholdGen() const=0
virtual void save(const String &filename) const
virtual bool empty() const
virtual void setShadowValue(int value)=0
virtual double getShadowThreshold() const=0
virtual void setVarMin(double varMin)=0
virtual double getBackgroundRatio() const=0
virtual void setBackgroundRatio(double ratio)=0
virtual double getVarThreshold() const=0
virtual void setDetectShadows(bool detectShadows)=0
virtual void setVarMax(double varMax)=0
Ptr< BackgroundSubtractorMOG2 > createBackgroundSubtractorMOG2(int history=500, double varThreshold=16, bool detectShadows=true)