17 map<int,Ptr<DualTVL1OpticalFlow> > obj_;
27 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
33 vector<MxArray> rhs(prhs, prhs+nrhs);
34 int id = rhs[0].toInt();
35 string method(rhs[1].toString());
38 if (method ==
"new") {
40 obj_[++last_id] = createOptFlow_DualTVL1();
46 Ptr<DualTVL1OpticalFlow> obj = obj_[id];
47 if (method ==
"delete") {
51 else if (method ==
"clear") {
55 else if (method ==
"save") {
57 obj->save(rhs[2].toString());
59 else if (method ==
"load") {
60 nargchk(nrhs>=3 && (nrhs%2)!=0 && nlhs==0);
62 bool loadFromString =
false;
63 for (
int i=3; i<nrhs; i+=2) {
64 string key(rhs[i].toString());
66 objname = rhs[i+1].toString();
67 else if (key==
"FromString")
68 loadFromString = rhs[i+1].toBool();
70 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
79 FileStorage fs(rhs[2].toString(), FileStorage::READ +
80 (loadFromString ? FileStorage::MEMORY : 0));
81 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
83 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
86 else if (method ==
"empty") {
88 plhs[0] =
MxArray(obj->empty());
90 else if (method ==
"getDefaultName") {
92 plhs[0] =
MxArray(obj->getDefaultName());
94 else if (method ==
"calc") {
95 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=1);
97 for (
int i=4; i<nrhs; i+=2) {
98 string key(rhs[i].toString());
99 if (key ==
"InitialFlow")
100 flow = rhs[i+1].toMat(CV_32F);
102 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
104 Mat I0(rhs[2].toMat(rhs[2].isSingle() ? CV_32F : CV_8U)),
105 I1(rhs[3].toMat(rhs[3].isSingle() ? CV_32F : CV_8U));
106 obj->calc(I0, I1, flow);
109 else if (method ==
"collectGarbage") {
111 obj->collectGarbage();
113 else if (method ==
"get") {
115 string prop(rhs[2].toString());
116 if (prop ==
"Epsilon")
117 plhs[0] =
MxArray(obj->getEpsilon());
118 else if (prop ==
"Gamma")
119 plhs[0] =
MxArray(obj->getGamma());
120 else if (prop ==
"InnerIterations")
121 plhs[0] =
MxArray(obj->getInnerIterations());
122 else if (prop ==
"Lambda")
123 plhs[0] =
MxArray(obj->getLambda());
124 else if (prop ==
"MedianFiltering")
125 plhs[0] =
MxArray(obj->getMedianFiltering());
126 else if (prop ==
"OuterIterations")
127 plhs[0] =
MxArray(obj->getOuterIterations());
128 else if (prop ==
"ScalesNumber")
129 plhs[0] =
MxArray(obj->getScalesNumber());
130 else if (prop ==
"ScaleStep")
131 plhs[0] =
MxArray(obj->getScaleStep());
132 else if (prop ==
"Tau")
133 plhs[0] =
MxArray(obj->getTau());
134 else if (prop ==
"Theta")
135 plhs[0] =
MxArray(obj->getTheta());
136 else if (prop ==
"UseInitialFlow")
137 plhs[0] =
MxArray(obj->getUseInitialFlow());
138 else if (prop ==
"WarpingsNumber")
139 plhs[0] =
MxArray(obj->getWarpingsNumber());
141 mexErrMsgIdAndTxt(
"mexopencv:error",
142 "Unrecognized property %s", prop.c_str());
144 else if (method ==
"set") {
146 string prop(rhs[2].toString());
147 if (prop ==
"Epsilon")
148 obj->setEpsilon(rhs[3].toDouble());
149 else if (prop ==
"Gamma")
150 obj->setGamma(rhs[3].toDouble());
151 else if (prop ==
"InnerIterations")
152 obj->setInnerIterations(rhs[3].toInt());
153 else if (prop ==
"Lambda")
154 obj->setLambda(rhs[3].toDouble());
155 else if (prop ==
"MedianFiltering")
156 obj->setMedianFiltering(rhs[3].toInt());
157 else if (prop ==
"OuterIterations")
158 obj->setOuterIterations(rhs[3].toInt());
159 else if (prop ==
"ScalesNumber")
160 obj->setScalesNumber(rhs[3].toInt());
161 else if (prop ==
"ScaleStep")
162 obj->setScaleStep(rhs[3].toDouble());
163 else if (prop ==
"Tau")
164 obj->setTau(rhs[3].toDouble());
165 else if (prop ==
"Theta")
166 obj->setTheta(rhs[3].toDouble());
167 else if (prop ==
"UseInitialFlow")
168 obj->setUseInitialFlow(rhs[3].toBool());
169 else if (prop ==
"WarpingsNumber")
170 obj->setWarpingsNumber(rhs[3].toInt());
172 mexErrMsgIdAndTxt(
"mexopencv:error",
173 "Unrecognized property %s", prop.c_str());
176 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized operation");
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.