9 #include "opencv2/ximgproc.hpp" 19 map<int,Ptr<GuidedFilter> > obj_;
31 OptionsParser(vector<MxArray>::const_iterator first,
32 vector<MxArray>::const_iterator last)
36 ptrdiff_t len = std::distance(first, last);
38 for (; first != last; first += 2) {
39 string key(first->toString());
40 const MxArray& val = *(first + 1);
43 else if (key ==
"EPS")
46 mexErrMsgIdAndTxt(
"mexopencv:error",
47 "Unrecognized option %s", key.c_str());
60 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
66 vector<MxArray> rhs(prhs, prhs+nrhs);
67 int id = rhs[0].toInt();
68 string method(rhs[1].toString());
71 if (method ==
"new") {
73 Mat guide(rhs[2].toMat(rhs[2].isUint8() ? CV_8U :
74 (rhs[2].isUint16() ? CV_16U : CV_32F)));
75 OptionsParser opts(rhs.begin() + 3, rhs.end());
76 obj_[++last_id] = createGuidedFilter(guide, opts.radius, opts.eps);
81 else if (method ==
"guidedFilter") {
83 Mat src(rhs[2].toMat(rhs[2].isUint8() ? CV_8U : CV_32F)),
84 guide(rhs[3].toMat(rhs[3].isUint8() ? CV_8U :
85 (rhs[3].isUint16() ? CV_16U : CV_32F))),
87 OptionsParser opts(rhs.begin() + 4, rhs.end());
88 guidedFilter(guide, src, dst, opts.radius, opts.eps);
94 Ptr<GuidedFilter> obj = obj_[id];
95 if (method ==
"delete") {
99 else if (method ==
"clear") {
103 else if (method ==
"load") {
104 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
106 bool loadFromString =
false;
107 for (
int i=3; i<nrhs; i+=2) {
108 string key(rhs[i].toString());
109 if (key ==
"ObjName")
110 objname = rhs[i+1].toString();
111 else if (key ==
"FromString")
112 loadFromString = rhs[i+1].toBool();
114 mexErrMsgIdAndTxt(
"mexopencv:error",
115 "Unrecognized option %s", key.c_str());
124 FileStorage fs(rhs[2].toString(), FileStorage::READ +
125 (loadFromString ? FileStorage::MEMORY : 0));
126 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
128 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
131 else if (method ==
"save") {
133 obj->save(rhs[2].toString());
135 else if (method ==
"empty") {
137 plhs[0] =
MxArray(obj->empty());
139 else if (method ==
"getDefaultName") {
141 plhs[0] =
MxArray(obj->getDefaultName());
143 else if (method ==
"filter") {
144 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
146 for (
int i=3; i<nrhs; i+=2) {
147 string key(rhs[i].toString());
149 dDepth = (rhs[i+1].isChar()) ?
152 mexErrMsgIdAndTxt(
"mexopencv:error",
153 "Unrecognized option %s", key.c_str());
155 Mat src(rhs[2].toMat(rhs[2].isUint8() ? CV_8U : CV_32F)),
157 obj->filter(src, dst, dDepth);
161 mexErrMsgIdAndTxt(
"mexopencv:error",
162 "Unrecognized operation %s", method.c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
int toInt() const
Convert MxArray to int.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.