9 #include "opencv2/ximgproc.hpp" 19 map<int,Ptr<GraphSegmentation> > 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") {
41 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
45 for (
int i=2; i<nrhs; i+=2) {
46 string key(rhs[i].toString());
48 sigma = rhs[i+1].toDouble();
50 k = rhs[i+1].toFloat();
51 else if (key ==
"MinSize")
52 min_size = rhs[i+1].toInt();
54 mexErrMsgIdAndTxt(
"mexopencv:error",
55 "Unrecognized option %s", key.c_str());
57 obj_[++last_id] = createGraphSegmentation(sigma, k, min_size);
63 Ptr<GraphSegmentation> obj = obj_[id];
64 if (method ==
"delete") {
68 else if (method ==
"clear") {
72 else if (method ==
"load") {
73 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
75 bool loadFromString =
false;
76 for (
int i=3; i<nrhs; i+=2) {
77 string key(rhs[i].toString());
79 objname = rhs[i+1].toString();
80 else if (key ==
"FromString")
81 loadFromString = rhs[i+1].toBool();
83 mexErrMsgIdAndTxt(
"mexopencv:error",
84 "Unrecognized option %s", key.c_str());
93 FileStorage fs(rhs[2].toString(), FileStorage::READ +
94 (loadFromString ? FileStorage::MEMORY : 0));
95 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
97 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
100 else if (method ==
"save") {
102 obj->save(rhs[2].toString());
104 else if (method ==
"empty") {
106 plhs[0] =
MxArray(obj->empty());
108 else if (method ==
"getDefaultName") {
110 plhs[0] =
MxArray(obj->getDefaultName());
112 else if (method ==
"processImage") {
114 Mat src(rhs[2].toMat()), dst;
115 obj->processImage(src, dst);
118 else if (method ==
"get") {
120 string prop(rhs[2].toString());
122 plhs[0] =
MxArray(obj->getSigma());
123 else if (prop ==
"K")
124 plhs[0] =
MxArray(obj->getK());
125 else if (prop ==
"MinSize")
126 plhs[0] =
MxArray(obj->getMinSize());
128 mexErrMsgIdAndTxt(
"mexopencv:error",
129 "Unrecognized property %s", prop.c_str());
131 else if (method ==
"set") {
133 string prop(rhs[2].toString());
135 obj->setSigma(rhs[3].toDouble());
136 else if (prop ==
"K")
137 obj->setK(rhs[3].toFloat());
138 else if (prop ==
"MinSize")
139 obj->setMinSize(rhs[3].toInt());
141 mexErrMsgIdAndTxt(
"mexopencv:error",
142 "Unrecognized property %s", prop.c_str());
145 mexErrMsgIdAndTxt(
"mexopencv:error",
146 "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.