9 #include "opencv2/ximgproc.hpp" 19 map<int,Ptr<EdgeAwareInterpolator> > obj_;
29 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
35 vector<MxArray> rhs(prhs, prhs+nrhs);
36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
42 obj_[++last_id] = createEdgeAwareInterpolator();
48 Ptr<EdgeAwareInterpolator> obj = obj_[id];
49 if (method ==
"delete") {
53 else if (method ==
"clear") {
57 else if (method ==
"load") {
58 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
60 bool loadFromString =
false;
61 for (
int i=3; i<nrhs; i+=2) {
62 string key(rhs[i].toString());
64 objname = rhs[i+1].toString();
65 else if (key ==
"FromString")
66 loadFromString = rhs[i+1].toBool();
68 mexErrMsgIdAndTxt(
"mexopencv:error",
69 "Unrecognized option %s", key.c_str());
78 FileStorage fs(rhs[2].toString(), FileStorage::READ +
79 (loadFromString ? FileStorage::MEMORY : 0));
80 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
82 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
85 else if (method ==
"save") {
87 obj->save(rhs[2].toString());
89 else if (method ==
"empty") {
91 plhs[0] =
MxArray(obj->empty());
93 else if (method ==
"getDefaultName") {
95 plhs[0] =
MxArray(obj->getDefaultName());
97 else if (method ==
"interpolate") {
99 Mat from_image(rhs[2].toMat(CV_8U)),
100 to_image(rhs[4].toMat(CV_8U)),
102 vector<Point2f> from_points(rhs[3].toVector<Point2f>()),
103 to_points(rhs[5].toVector<Point2f>());
104 obj->interpolate(from_image, from_points,
105 to_image, to_points, dense_flow);
108 else if (method ==
"get") {
110 string prop(rhs[2].toString());
112 plhs[0] =
MxArray(obj->getK());
113 else if (prop ==
"Sigma")
114 plhs[0] =
MxArray(obj->getSigma());
115 else if (prop ==
"Lambda")
116 plhs[0] =
MxArray(obj->getLambda());
117 else if (prop ==
"UsePostProcessing")
118 plhs[0] =
MxArray(obj->getUsePostProcessing());
119 else if (prop ==
"FGSLambda")
120 plhs[0] =
MxArray(obj->getFGSLambda());
121 else if (prop ==
"FGSSigma")
122 plhs[0] =
MxArray(obj->getFGSSigma());
124 mexErrMsgIdAndTxt(
"mexopencv:error",
125 "Unrecognized property %s", prop.c_str());
127 else if (method ==
"set") {
129 string prop(rhs[2].toString());
131 obj->setK(rhs[3].toInt());
132 else if (prop ==
"Sigma")
133 obj->setSigma(rhs[3].toFloat());
134 else if (prop ==
"Lambda")
135 obj->setLambda(rhs[3].toFloat());
136 else if (prop ==
"UsePostProcessing")
137 obj->setUsePostProcessing(rhs[3].toBool());
138 else if (prop ==
"FGSLambda")
139 obj->setFGSLambda(rhs[3].toFloat());
140 else if (prop ==
"FGSSigma")
141 obj->setFGSSigma(rhs[3].toFloat());
143 mexErrMsgIdAndTxt(
"mexopencv:error",
144 "Unrecognized property %s", prop.c_str());
147 mexErrMsgIdAndTxt(
"mexopencv:error",
148 "Unrecognized operation %s", method.c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.