20 s.set(
"TypeId",
string(
typeid(*p).name()));
21 s.set(
"NDummies", p->getNDummies());
22 s.set(
"DefaultCost", p->getDefaultCost());
24 Ptr<NormHistogramCostExtractor> pp = p.dynamicCast<NormHistogramCostExtractor>();
29 Ptr<EMDHistogramCostExtractor> pp = p.dynamicCast<EMDHistogramCostExtractor>();
41 s.set(
"TypeId",
string(
typeid(*p).name()));
43 Ptr<ThinPlateSplineShapeTransformer> pp = p.dynamicCast<ThinPlateSplineShapeTransformer>();
45 s.set(
"RegularizationParameter", pp->getRegularizationParameter());
48 Ptr<AffineTransformer> pp = p.dynamicCast<AffineTransformer>();
50 s.set(
"FullAffine", pp->getFullAffine());
60 vector<MxArray>::const_iterator first,
61 vector<MxArray>::const_iterator last)
63 ptrdiff_t len = std::distance(first, last);
65 int flag = cv::DIST_L2;
67 float defaultCost = 0.2f;
68 for (; first != last; first += 2) {
69 string key(first->toString());
70 const MxArray& val = *(first + 1);
71 if (key ==
"NDummies")
72 nDummies = val.
toInt();
73 else if (key ==
"DefaultCost")
74 defaultCost = val.toFloat();
75 else if (key ==
"NormFlag")
78 mexErrMsgIdAndTxt(
"mexopencv:error",
79 "Unrecognized option %s", key.c_str());
81 return createNormHistogramCostExtractor(flag, nDummies, defaultCost);
85 vector<MxArray>::const_iterator first,
86 vector<MxArray>::const_iterator last)
88 ptrdiff_t len = std::distance(first, last);
90 int flag = cv::DIST_L2;
92 float defaultCost = 0.2f;
93 for (; first != last; first += 2) {
94 string key(first->toString());
95 const MxArray& val = *(first + 1);
96 if (key ==
"NDummies")
97 nDummies = val.
toInt();
98 else if (key ==
"DefaultCost")
99 defaultCost = val.toFloat();
100 else if (key ==
"NormFlag")
103 mexErrMsgIdAndTxt(
"mexopencv:error",
104 "Unrecognized option %s", key.c_str());
106 return createEMDHistogramCostExtractor(flag, nDummies, defaultCost);
110 vector<MxArray>::const_iterator first,
111 vector<MxArray>::const_iterator last)
113 ptrdiff_t len = std::distance(first, last);
116 float defaultCost = 0.2f;
117 for (; first != last; first += 2) {
118 string key(first->toString());
119 const MxArray& val = *(first + 1);
120 if (key ==
"NDummies")
121 nDummies = val.
toInt();
122 else if (key ==
"DefaultCost")
123 defaultCost = val.toFloat();
125 mexErrMsgIdAndTxt(
"mexopencv:error",
126 "Unrecognized option %s", key.c_str());
128 return createChiHistogramCostExtractor(nDummies, defaultCost);
132 vector<MxArray>::const_iterator first,
133 vector<MxArray>::const_iterator last)
135 ptrdiff_t len = std::distance(first, last);
138 float defaultCost = 0.2f;
139 for (; first != last; first += 2) {
140 string key(first->toString());
141 const MxArray& val = *(first + 1);
142 if (key ==
"NDummies")
143 nDummies = val.
toInt();
144 else if (key ==
"DefaultCost")
145 defaultCost = val.toFloat();
147 mexErrMsgIdAndTxt(
"mexopencv:error",
148 "Unrecognized option %s", key.c_str());
150 return createEMDL1HistogramCostExtractor(nDummies, defaultCost);
155 vector<MxArray>::const_iterator first,
156 vector<MxArray>::const_iterator last)
158 Ptr<HistogramCostExtractor> p;
159 if (type ==
"NormHistogramCostExtractor")
161 else if (type ==
"EMDHistogramCostExtractor")
163 else if (type ==
"ChiHistogramCostExtractor")
165 else if (type ==
"EMDL1HistogramCostExtractor")
168 mexErrMsgIdAndTxt(
"mexopencv:error",
169 "Unrecognized histogram cost extractor %s", type.c_str());
171 mexErrMsgIdAndTxt(
"mexopencv:error",
172 "Failed to create HistogramCostExtractor");
177 vector<MxArray>::const_iterator first,
178 vector<MxArray>::const_iterator last)
180 ptrdiff_t len = std::distance(first, last);
182 double regularizationParameter = 0;
183 for (; first != last; first += 2) {
184 string key(first->toString());
185 const MxArray& val = *(first + 1);
186 if (key ==
"RegularizationParameter")
187 regularizationParameter = val.
toDouble();
189 mexErrMsgIdAndTxt(
"mexopencv:error",
190 "Unrecognized option %s", key.c_str());
192 return createThinPlateSplineShapeTransformer(regularizationParameter);
196 vector<MxArray>::const_iterator first,
197 vector<MxArray>::const_iterator last)
199 ptrdiff_t len = std::distance(first, last);
201 bool fullAffine =
true;
202 for (; first != last; first += 2) {
203 string key(first->toString());
204 const MxArray& val = *(first + 1);
205 if (key ==
"FullAffine")
206 fullAffine = val.
toBool();
208 mexErrMsgIdAndTxt(
"mexopencv:error",
209 "Unrecognized option %s", key.c_str());
211 return createAffineTransformer(fullAffine);
216 vector<MxArray>::const_iterator first,
217 vector<MxArray>::const_iterator last)
219 Ptr<ShapeTransformer> p;
220 if (type ==
"ThinPlateSplineShapeTransformer")
222 else if (type ==
"AffineTransformer")
225 mexErrMsgIdAndTxt(
"mexopencv:error",
226 "Unrecognized shape transformer %s", type.c_str());
228 mexErrMsgIdAndTxt(
"mexopencv:error",
229 "Failed to create ShapeTransformer");
234 vector<MxArray>::const_iterator first,
235 vector<MxArray>::const_iterator last)
237 ptrdiff_t len = std::distance(first, last);
239 int nAngularBins = 12;
241 float innerRadius = 0.2f;
242 float outerRadius = 2;
244 Ptr<HistogramCostExtractor> comparer;
245 Ptr<ShapeTransformer> transformer;
246 for (; first != last; first += 2) {
247 string key(first->toString());
248 const MxArray& val = *(first + 1);
249 if (key ==
"AngularBins")
250 nAngularBins = val.
toInt();
251 else if (key ==
"RadialBins")
252 nRadialBins = val.toInt();
253 else if (key ==
"InnerRadius")
254 innerRadius = val.toFloat();
255 else if (key ==
"OuterRadius")
256 outerRadius = val.toFloat();
257 else if (key ==
"Iterations")
258 iterations = val.toInt();
259 else if (key ==
"CostExtractor") {
260 vector<MxArray> args(val.toVector<
MxArray>());
263 args[0].toString(), args.begin() + 1, args.end());
265 else if (key ==
"TransformAlgorithm") {
266 vector<MxArray> args(val.toVector<
MxArray>());
269 args[0].toString(), args.begin() + 1, args.end());
272 mexErrMsgIdAndTxt(
"mexopencv:error",
273 "Unrecognized option %s", key.c_str());
275 if (comparer.empty())
276 comparer = createChiHistogramCostExtractor();
277 if (transformer.empty())
278 transformer = createThinPlateSplineShapeTransformer();
279 return createShapeContextDistanceExtractor(nAngularBins, nRadialBins,
280 innerRadius, outerRadius, iterations, comparer, transformer);
284 vector<MxArray>::const_iterator first,
285 vector<MxArray>::const_iterator last)
287 ptrdiff_t len = std::distance(first, last);
289 int distanceFlag = cv::NORM_L2;
290 float rankProp = 0.6f;
291 for (; first != last; first += 2) {
292 string key(first->toString());
293 const MxArray& val = *(first + 1);
294 if (key ==
"DistanceFlag")
295 distanceFlag =
NormType[val.toString()];
296 else if (key ==
"RankProportion")
297 rankProp = val.toFloat();
299 mexErrMsgIdAndTxt(
"mexopencv:error",
300 "Unrecognized option %s", key.c_str());
302 return createHausdorffDistanceExtractor(distanceFlag, rankProp);
Common definitions for the shape module.
cv::Ptr< cv::HistogramCostExtractor > create_EMDHistogramCostExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of EMDHistogramCostExtractor using options in arguments.
cv::Ptr< cv::ShapeTransformer > create_ShapeTransformer(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ShapeTransformer using options in arguments.
cv::Ptr< cv::HistogramCostExtractor > create_NormHistogramCostExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of NormHistogramCostExtractor using options in arguments.
cv::Ptr< cv::AffineTransformer > create_AffineTransformer(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of AffineTransformer using options in arguments.
const ConstMap< int, std::string > DistTypeInv
Inverse Distance types for Distance Transform and M-estimators.
MxArray toStruct(const std::vector< cv::ml::DTrees::Node > &nodes)
Convert tree nodes to struct array.
cv::Ptr< cv::ThinPlateSplineShapeTransformer > create_ThinPlateSplineShapeTransformer(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ThinPlateSplineShapeTransformer using options in arguments. ...
double toDouble() const
Convert MxArray to double.
int toInt() const
Convert MxArray to int.
cv::Ptr< cv::HistogramCostExtractor > create_ChiHistogramCostExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ChiHistogramCostExtractor using options in arguments.
cv::Ptr< cv::HistogramCostExtractor > create_EMDL1HistogramCostExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of EMDL1HistogramCostExtractor using options in arguments.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
bool toBool() const
Convert MxArray to bool.
const ConstMap< std::string, int > DistType
Distance types for Distance Transform and M-estimators.
cv::Ptr< cv::ShapeContextDistanceExtractor > create_ShapeContextDistanceExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ShapeContextDistanceExtractor using options in arguments.
cv::Ptr< cv::HausdorffDistanceExtractor > create_HausdorffDistanceExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of HausdorffDistanceExtractor using options in arguments.
const ConstMap< std::string, int > NormType
Norm type map for option processing.
cv::Ptr< cv::HistogramCostExtractor > create_HistogramCostExtractor(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of HistogramCostExtractor using options in arguments.