19 map<int,Ptr<MSER> > 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] =
createMSER(rhs.begin() + 2, rhs.end());
48 Ptr<MSER> obj = obj_[id];
49 if (method ==
"delete") {
53 else if (method ==
"typeid") {
55 plhs[0] =
MxArray(
string(
typeid(*obj).name()));
57 else if (method ==
"clear") {
61 else if (method ==
"load") {
62 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
64 bool loadFromString =
false;
65 for (
int i=3; i<nrhs; i+=2) {
66 string key(rhs[i].toString());
68 objname = rhs[i+1].toString();
69 else if (key ==
"FromString")
70 loadFromString = rhs[i+1].toBool();
72 mexErrMsgIdAndTxt(
"mexopencv:error",
73 "Unrecognized option %s", key.c_str());
75 obj_[id] = (loadFromString ?
76 Algorithm::loadFromString<MSER>(rhs[2].toString(), objname) :
77 Algorithm::load<MSER>(rhs[2].toString(), objname));
79 else if (method ==
"save") {
81 obj->save(rhs[2].toString());
83 else if (method ==
"empty") {
85 plhs[0] =
MxArray(obj->empty());
87 else if (method ==
"getDefaultName") {
89 plhs[0] =
MxArray(obj->getDefaultName());
91 else if (method ==
"detect") {
92 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
93 if (rhs[2].isNumeric()) {
95 for (
int i=3; i<nrhs; i+=2) {
96 string key(rhs[i].toString());
98 mask = rhs[i+1].toMat(CV_8U);
100 mexErrMsgIdAndTxt(
"mexopencv:error",
101 "Unrecognized option %s", key.c_str());
103 Mat image(rhs[2].toMat(CV_8U));
104 vector<KeyPoint> keypoints;
105 obj->detect(image, keypoints, mask);
108 else if (rhs[2].isCell()) {
110 for (
int i=3; i<nrhs; i+=2) {
111 string key(rhs[i].toString());
114 vector<MxArray> arr(rhs[i+1].toVector<MxArray>());
116 masks.reserve(arr.size());
117 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
118 masks.push_back(it->toMat(CV_8U));
121 mexErrMsgIdAndTxt(
"mexopencv:error",
122 "Unrecognized option %s", key.c_str());
127 vector<MxArray> arr(rhs[2].toVector<MxArray>());
128 images.reserve(arr.size());
129 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
130 images.push_back(it->toMat(CV_8U));
132 vector<vector<KeyPoint> > keypoints;
133 obj->detect(images, keypoints, masks);
137 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
139 else if (method ==
"detectRegions") {
141 Mat image(rhs[2].toMat(CV_8U));
142 vector<vector<Point> > msers;
144 obj->detectRegions(image, msers, bboxes);
149 else if (method ==
"get") {
151 string prop(rhs[2].toString());
153 plhs[0] =
MxArray(obj->getDelta());
154 else if (prop ==
"MaxArea")
155 plhs[0] =
MxArray(obj->getMaxArea());
156 else if (prop ==
"MinArea")
157 plhs[0] =
MxArray(obj->getMinArea());
158 else if (prop ==
"Pass2Only")
159 plhs[0] =
MxArray(obj->getPass2Only());
161 mexErrMsgIdAndTxt(
"mexopencv:error",
162 "Unrecognized property %s", prop.c_str());
164 else if (method ==
"set") {
166 string prop(rhs[2].toString());
168 obj->setDelta(rhs[3].toInt());
169 else if (prop ==
"MaxArea")
170 obj->setMaxArea(rhs[3].toInt());
171 else if (prop ==
"MinArea")
172 obj->setMinArea(rhs[3].toInt());
173 else if (prop ==
"Pass2Only")
174 obj->setPass2Only(rhs[3].toBool());
176 mexErrMsgIdAndTxt(
"mexopencv:error",
177 "Unrecognized property %s", prop.c_str());
185 mexErrMsgIdAndTxt(
"mexopencv:error",
186 "Unrecognized operation %s",method.c_str());
cv::Ptr< cv::MSER > createMSER(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of MSER using options in arguments.
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.
Common definitions for the features2d and xfeatures2d modules.
Global constant definitions.