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 dist2Threshold = 400.0;
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 ==
"Dist2Threshold")
49 dist2Threshold = rhs[i+1].toDouble();
50 else if (key ==
"DetectShadows")
51 detectShadows = rhs[i+1].toBool();
54 "Unrecognized option %s", key.
c_str());
57 history, dist2Threshold, 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 ==
"NSamples")
147 else if (prop ==
"kNNSamples")
149 else if (prop ==
"Dist2Threshold")
151 else if (prop ==
"DetectShadows")
153 else if (prop ==
"ShadowValue")
155 else if (prop ==
"ShadowThreshold")
159 "Unrecognized property %s", prop.
c_str());
161 else if (method ==
"set") {
163 string prop(rhs[2].toString());
164 if (prop ==
"History")
166 else if (prop ==
"NSamples")
168 else if (prop ==
"kNNSamples")
170 else if (prop ==
"Dist2Threshold")
172 else if (prop ==
"DetectShadows")
174 else if (prop ==
"ShadowValue")
176 else if (prop ==
"ShadowThreshold")
180 "Unrecognized property %s", prop.
c_str());
184 "Unrecognized operation %s", method.
c_str());
virtual bool getDetectShadows() const=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1)=0
map< int, Ptr< BackgroundSubtractorKNN > > obj_
Object container.
virtual bool isOpened() const
virtual double getShadowThreshold() const=0
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual void getBackgroundImage(OutputArray backgroundImage) const=0
virtual void setShadowValue(int value)=0
virtual double getDist2Threshold() const=0
virtual void setHistory(int history)=0
virtual void read(const FileNode &fn)
virtual int getShadowValue() const=0
virtual int getNSamples() 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...
virtual void setNSamples(int _nN)=0
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
virtual int getkNNSamples() const=0
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
virtual void setkNNSamples(int _nkNN)=0
int last_id
Last object id to allocate.
FileNode getFirstTopLevelNode() const
virtual String getDefaultName() const
Global constant definitions.
virtual void setShadowThreshold(double threshold)=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual void setDist2Threshold(double _dist2Threshold)=0
virtual void save(const String &filename) const
virtual bool empty() const
virtual void setDetectShadows(bool detectShadows)=0
Ptr< BackgroundSubtractorKNN > createBackgroundSubtractorKNN(int history=500, double dist2Threshold=400.0, bool detectShadows=true)
virtual int getHistory() const=0