17 map<int,Ptr<GeneralizedHoughGuil> > 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] = createGeneralizedHoughGuil();
46 Ptr<GeneralizedHoughGuil> obj = obj_[id];
47 if (method ==
"delete") {
51 else if (method ==
"clear") {
55 else if (method ==
"load") {
56 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
58 bool loadFromString =
false;
59 for (
int i=3; i<nrhs; i+=2) {
60 string key(rhs[i].toString());
62 objname = rhs[i+1].toString();
63 else if (key==
"FromString")
64 loadFromString = rhs[i+1].toBool();
66 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option %s", key.c_str());
75 FileStorage fs(rhs[2].toString(), FileStorage::READ +
76 (loadFromString ? FileStorage::MEMORY : 0));
77 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
79 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
82 else if (method ==
"save") {
84 obj->save(rhs[2].toString());
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 ==
"detect") {
95 nargchk((nrhs==3 || nrhs==5) && nlhs<=2);
96 vector<Vec4f> positions;
99 Mat image(rhs[2].toMat(CV_8U));
100 obj->detect(image, positions, (nlhs>1) ? votes : noArray());
103 Mat edges(rhs[2].toMat(CV_8U)),
104 dx(rhs[3].toMat(CV_32F)),
105 dy(rhs[4].toMat(CV_32F));
106 obj->detect(edges, dx, dy, positions, (nlhs>1) ? votes : noArray());
112 else if (method ==
"setTemplate") {
113 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
114 bool edges_variant = (nrhs>=5 && rhs[3].isNumeric() && rhs[4].isNumeric());
115 Point templCenter(-1,-1);
116 for (
int i=(edges_variant ? 5 : 3); i<nrhs; i+=2) {
117 string key(rhs[i].toString());
119 templCenter = rhs[i+1].toPoint();
121 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
124 Mat edges(rhs[2].toMat(CV_8U)),
125 dx(rhs[3].toMat(CV_32F)),
126 dy(rhs[4].toMat(CV_32F));
127 obj->setTemplate(edges, dx, dy, templCenter);
130 Mat templ(rhs[2].toMat(CV_8U));
131 obj->setTemplate(templ, templCenter);
134 else if (method ==
"get") {
136 string prop(rhs[2].toString());
137 if (prop ==
"CannyHighThresh")
138 plhs[0] =
MxArray(obj->getCannyHighThresh());
139 else if (prop ==
"CannyLowThresh")
140 plhs[0] =
MxArray(obj->getCannyLowThresh());
141 else if (prop ==
"Dp")
142 plhs[0] =
MxArray(obj->getDp());
143 else if (prop ==
"MaxBufferSize")
144 plhs[0] =
MxArray(obj->getMaxBufferSize());
145 else if (prop ==
"MinDist")
146 plhs[0] =
MxArray(obj->getMinDist());
147 else if (prop ==
"AngleEpsilon")
148 plhs[0] =
MxArray(obj->getAngleEpsilon());
149 else if (prop ==
"AngleStep")
150 plhs[0] =
MxArray(obj->getAngleStep());
151 else if (prop ==
"AngleThresh")
152 plhs[0] =
MxArray(obj->getAngleThresh());
153 else if (prop ==
"Levels")
154 plhs[0] =
MxArray(obj->getLevels());
155 else if (prop ==
"MaxAngle")
156 plhs[0] =
MxArray(obj->getMaxAngle());
157 else if (prop ==
"MaxScale")
158 plhs[0] =
MxArray(obj->getMaxScale());
159 else if (prop ==
"MinAngle")
160 plhs[0] =
MxArray(obj->getMinAngle());
161 else if (prop ==
"MinScale")
162 plhs[0] =
MxArray(obj->getMinScale());
163 else if (prop ==
"PosThresh")
164 plhs[0] =
MxArray(obj->getPosThresh());
165 else if (prop ==
"ScaleStep")
166 plhs[0] =
MxArray(obj->getScaleStep());
167 else if (prop ==
"ScaleThresh")
168 plhs[0] =
MxArray(obj->getScaleThresh());
169 else if (prop ==
"Xi")
170 plhs[0] =
MxArray(obj->getXi());
172 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized property %s", prop.c_str());
174 else if (method ==
"set") {
176 string prop(rhs[2].toString());
177 if (prop ==
"CannyHighThresh")
178 obj->setCannyHighThresh(rhs[3].toInt());
179 else if (prop ==
"CannyLowThresh")
180 obj->setCannyLowThresh(rhs[3].toInt());
181 else if (prop ==
"Dp")
182 obj->setDp(rhs[3].toDouble());
183 else if (prop ==
"MaxBufferSize")
184 obj->setMaxBufferSize(rhs[3].toInt());
185 else if (prop ==
"MinDist")
186 obj->setMinDist(rhs[3].toDouble());
187 else if (prop ==
"AngleEpsilon")
188 obj->setAngleEpsilon(rhs[3].toDouble());
189 else if (prop ==
"AngleStep")
190 obj->setAngleStep(rhs[3].toDouble());
191 else if (prop ==
"AngleThresh")
192 obj->setAngleThresh(rhs[3].toInt());
193 else if (prop ==
"Levels")
194 obj->setLevels(rhs[3].toInt());
195 else if (prop ==
"MaxAngle")
196 obj->setMaxAngle(rhs[3].toDouble());
197 else if (prop ==
"MaxScale")
198 obj->setMaxScale(rhs[3].toDouble());
199 else if (prop ==
"MinAngle")
200 obj->setMinAngle(rhs[3].toDouble());
201 else if (prop ==
"MinScale")
202 obj->setMinScale(rhs[3].toDouble());
203 else if (prop ==
"PosThresh")
204 obj->setPosThresh(rhs[3].toInt());
205 else if (prop ==
"ScaleStep")
206 obj->setScaleStep(rhs[3].toDouble());
207 else if (prop ==
"ScaleThresh")
208 obj->setScaleThresh(rhs[3].toInt());
209 else if (prop ==
"Xi")
210 obj->setXi(rhs[3].toDouble());
212 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized property %s", prop.c_str());
215 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized operation");
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.