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);
42 int initializationFrames = 120;
43 double decisionThreshold = 0.8;
44 for (
int i=2; i<nrhs; i+=2) {
45 string key(rhs[i].toString());
46 if (key ==
"InitializationFrames")
47 initializationFrames = rhs[i+1].toInt();
48 else if (key ==
"DecisionThreshold")
49 decisionThreshold = rhs[i+1].toDouble();
52 "Unrecognized option %s", key.
c_str());
55 initializationFrames, decisionThreshold);
65 if (method ==
"delete") {
70 else if (method ==
"clear") {
74 else if (method ==
"save") {
76 obj->
save(rhs[2].toString());
78 else if (method ==
"load") {
79 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
81 bool loadFromString =
false;
82 for (
int i=3; i<nrhs; i+=2) {
83 string key(rhs[i].toString());
85 objname = rhs[i+1].toString();
86 else if (key ==
"FromString")
87 loadFromString = rhs[i+1].toBool();
90 "Unrecognized option %s", key.
c_str());
99 FileStorage fs(rhs[2].toString(), FileStorage::READ +
100 (loadFromString ? FileStorage::MEMORY : 0));
109 else if (method ==
"empty") {
113 else if (method ==
"getDefaultName") {
117 else if (method ==
"apply") {
118 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
119 double learningRate = -1;
120 for (
int i=3; i<nrhs; i+=2) {
121 string key(rhs[i].toString());
122 if (key ==
"LearningRate")
123 learningRate = rhs[i+1].toDouble();
126 "Unrecognized option %s", key.
c_str());
130 obj->
apply(image, fgmask, learningRate);
133 else if (method ==
"getBackgroundImage") {
137 plhs[0] =
MxArray(backgroundImage);
139 else if (method ==
"get") {
141 string prop(rhs[2].toString());
142 if (prop ==
"MaxFeatures")
144 else if (prop ==
"DefaultLearningRate")
146 else if (prop ==
"NumFrames")
148 else if (prop ==
"QuantizationLevels")
150 else if (prop ==
"BackgroundPrior")
152 else if (prop ==
"SmoothingRadius")
154 else if (prop ==
"DecisionThreshold")
156 else if (prop ==
"UpdateBackgroundModel")
158 else if (prop ==
"MinVal")
160 else if (prop ==
"MaxVal")
164 "Unrecognized property %s", prop.
c_str());
166 else if (method ==
"set") {
168 string prop(rhs[2].toString());
169 if (prop ==
"MaxFeatures")
171 else if (prop ==
"DefaultLearningRate")
173 else if (prop ==
"NumFrames")
175 else if (prop ==
"QuantizationLevels")
177 else if (prop ==
"BackgroundPrior")
179 else if (prop ==
"SmoothingRadius")
181 else if (prop ==
"DecisionThreshold")
183 else if (prop ==
"UpdateBackgroundModel")
185 else if (prop ==
"MinVal")
187 else if (prop ==
"MaxVal")
191 "Unrecognized property %s", prop.
c_str());
195 "Unrecognized operation %s", method.
c_str());
virtual void setMaxFeatures(int maxFeatures)=0
virtual void setQuantizationLevels(int nlevels)=0
virtual void setMinVal(double val)=0
virtual void setSmoothingRadius(int radius)=0
virtual bool getUpdateBackgroundModel() const=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
int last_id
Last object id to allocate.
virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1)=0
Ptr< cuda::BackgroundSubtractorGMG > createBackgroundSubtractorGMG(int initializationFrames=120, double decisionThreshold=0.8)
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual int getMaxFeatures() const=0
virtual double getMinVal() const=0
virtual void getBackgroundImage(OutputArray backgroundImage) const=0
virtual void read(const FileNode &fn)
virtual double getMaxVal() const=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...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
virtual int getNumFrames() const=0
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
virtual int getSmoothingRadius() const=0
FileNode getFirstTopLevelNode() const
virtual String getDefaultName() const
Global constant definitions.
virtual double getDefaultLearningRate() const=0
virtual void setDefaultLearningRate(double lr)=0
virtual void setDecisionThreshold(double thresh)=0
virtual void setUpdateBackgroundModel(bool update)=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual double getBackgroundPrior() const=0
virtual void save(const String &filename) const
virtual bool empty() const
virtual double getDecisionThreshold() const=0
virtual int getQuantizationLevels() const=0
map< int, Ptr< BackgroundSubtractorGMG > > obj_
Object container.
virtual void setNumFrames(int nframes)=0
virtual void setBackgroundPrior(double bgprior)=0
virtual void setMaxVal(double val)=0