17 map<int,Ptr<GeneralizedHoughBallard> > 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] = createGeneralizedHoughBallard();
46 Ptr<GeneralizedHoughBallard> 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 ==
"Levels")
148 plhs[0] =
MxArray(obj->getLevels());
149 else if (prop ==
"VotesThreshold")
150 plhs[0] =
MxArray(obj->getVotesThreshold());
152 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized property %s", prop.c_str());
154 else if (method ==
"set") {
156 string prop(rhs[2].toString());
157 if (prop ==
"CannyHighThresh")
158 obj->setCannyHighThresh(rhs[3].toInt());
159 else if (prop ==
"CannyLowThresh")
160 obj->setCannyLowThresh(rhs[3].toInt());
161 else if (prop ==
"Dp")
162 obj->setDp(rhs[3].toDouble());
163 else if (prop ==
"MaxBufferSize")
164 obj->setMaxBufferSize(rhs[3].toInt());
165 else if (prop ==
"MinDist")
166 obj->setMinDist(rhs[3].toDouble());
167 else if (prop ==
"Levels")
168 obj->setLevels(rhs[3].toInt());
169 else if (prop ==
"VotesThreshold")
170 obj->setVotesThreshold(rhs[3].toInt());
172 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized property %s", prop.c_str());
175 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.