mexopencv  3.4.1
MEX interface for OpenCV library
mexopencv_features2d.cpp
Go to the documentation of this file.
1 
10 using std::vector;
11 using std::string;
12 using namespace cv;
13 
14 #ifdef HAVE_OPENCV_XFEATURES2D
15 using namespace cv::xfeatures2d;
16 #endif
17 
18 
19 /**************************************************************\
20 * Feature Detection and Description *
21 \**************************************************************/
22 
26 {
27  ptrdiff_t len = std::distance(first, last);
28  nargchk((len % 2) == 0);
29  // second/third variants for a custom pattern
30  if (len >= 2 && !first->isChar()) {
31  vector<float> radiusList(first->toVector<float>()); ++first;
32  vector<int> numberList(first->toVector<int>()); ++first;
33  int thresh = 20;
34  int octaves = 3;
35  float dMax = 5.85f, dMin = 8.2f;
36  vector<int> indexChange;
37  for (; first != last; first += 2) {
38  string key((*first).toString());
39  const MxArray& val = *(first + 1);
40  if (key == "Threshold")
41  thresh = val.toInt();
42  else if (key == "Octaves")
43  octaves = val.toInt();
44  else if (key == "DMax")
45  dMax = val.toFloat();
46  else if (key == "DMin")
47  dMin = val.toFloat();
48  else if (key == "IndexChange")
49  indexChange = val.toVector<int>();
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54  return BRISK::create(thresh, octaves,
55  radiusList, numberList, dMax, dMin, indexChange);
56  }
57  // first variant
58  else {
59  int thresh = 30;
60  int octaves = 3;
61  float patternScale = 1.0f;
62  for (; first != last; first += 2) {
63  string key((*first).toString());
64  const MxArray& val = *(first + 1);
65  if (key == "Threshold")
66  thresh = val.toInt();
67  else if (key == "Octaves")
68  octaves = val.toInt();
69  else if (key == "PatternScale")
70  patternScale = val.toFloat();
71  else
72  mexErrMsgIdAndTxt("mexopencv:error",
73  "Unrecognized option %s", key.c_str());
74  }
75  return BRISK::create(thresh, octaves, patternScale);
76  }
77 }
78 
82 {
83  nargchk((std::distance(first, last) % 2) == 0);
84  int nfeatures = 500;
85  float scaleFactor = 1.2f;
86  int nlevels = 8;
87  int edgeThreshold = 31;
88  int firstLevel = 0;
89  int WTA_K = 2;
90  int scoreType = ORB::HARRIS_SCORE;
91  int patchSize = 31;
92  int fastThreshold = 20;
93  for (; first != last; first += 2) {
94  string key((*first).toString());
95  const MxArray& val = *(first + 1);
96  if (key == "MaxFeatures")
97  nfeatures = val.toInt();
98  else if (key == "ScaleFactor")
99  scaleFactor = val.toFloat();
100  else if (key == "NLevels")
101  nlevels = val.toInt();
102  else if (key == "EdgeThreshold")
103  edgeThreshold = val.toInt();
104  else if (key == "FirstLevel")
105  firstLevel = val.toInt();
106  else if (key == "WTA_K")
107  WTA_K = val.toInt();
108  else if (key == "ScoreType")
109  scoreType = ORBScoreType[val.toString()];
110  else if (key == "PatchSize")
111  patchSize = val.toInt();
112  else if (key == "FastThreshold")
113  fastThreshold = val.toInt();
114  else
115  mexErrMsgIdAndTxt("mexopencv:error",
116  "Unrecognized option %s", key.c_str());
117  }
118  return ORB::create(nfeatures, scaleFactor, nlevels, edgeThreshold,
119  firstLevel, WTA_K, scoreType, patchSize, fastThreshold);
120 }
121 
125 {
126  nargchk((std::distance(first, last) % 2) == 0);
127  int delta = 5;
128  int min_area = 60;
129  int max_area = 14400;
130  double max_variation = 0.25;
131  double min_diversity = 0.2;
132  int max_evolution = 200;
133  double area_threshold = 1.01;
134  double min_margin = 0.003;
135  int edge_blur_size = 5;
136  for (; first != last; first += 2) {
137  string key((*first).toString());
138  const MxArray& val = *(first + 1);
139  if (key == "Delta")
140  delta = val.toInt();
141  else if (key == "MinArea")
142  min_area = val.toInt();
143  else if (key == "MaxArea")
144  max_area = val.toInt();
145  else if (key == "MaxVariation")
146  max_variation = val.toDouble();
147  else if (key == "MinDiversity")
148  min_diversity = val.toDouble();
149  else if (key == "MaxEvolution")
150  max_evolution = val.toInt();
151  else if (key == "AreaThreshold")
152  area_threshold = val.toDouble();
153  else if (key == "MinMargin")
154  min_margin = val.toDouble();
155  else if (key == "EdgeBlurSize")
156  edge_blur_size = val.toInt();
157  else
158  mexErrMsgIdAndTxt("mexopencv:error",
159  "Unrecognized option %s", key.c_str());
160  }
161  return MSER::create(delta, min_area, max_area, max_variation,
162  min_diversity, max_evolution, area_threshold, min_margin,
163  edge_blur_size);
164 }
165 
169 {
170  nargchk((std::distance(first, last) % 2) == 0);
171  int threshold = 10;
172  bool nonmaxSuppression = true;
174  for (; first != last; first += 2) {
175  string key((*first).toString());
176  const MxArray& val = *(first + 1);
177  if (key == "Threshold")
178  threshold = val.toInt();
179  else if (key == "NonmaxSuppression")
180  nonmaxSuppression = val.toBool();
181  else if (key == "Type")
182  type = FASTTypeMap[val.toString()];
183  else
184  mexErrMsgIdAndTxt("mexopencv:error",
185  "Unrecognized option %s", key.c_str());
186  }
187  return FastFeatureDetector::create(threshold, nonmaxSuppression, type);
188 }
189 
193 {
194  nargchk((std::distance(first, last) % 2) == 0);
195  int maxCorners = 1000;
196  double qualityLevel = 0.01;
197  double minDistance = 1;
198  int blockSize = 3;
199  int gradientSize = 3;
200  bool useHarrisDetector = false;
201  double k = 0.04;
202  for (; first != last; first += 2) {
203  string key((*first).toString());
204  const MxArray& val = *(first + 1);
205  if (key == "MaxFeatures")
206  maxCorners = val.toInt();
207  else if (key == "QualityLevel")
208  qualityLevel = val.toDouble();
209  else if (key == "MinDistance")
210  minDistance = val.toDouble();
211  else if (key == "BlockSize")
212  blockSize = val.toInt();
213  else if (key == "GradientSize")
214  gradientSize = val.toInt();
215  else if (key == "HarrisDetector")
216  useHarrisDetector = val.toBool();
217  else if(key == "K")
218  k = val.toDouble();
219  else
220  mexErrMsgIdAndTxt("mexopencv:error",
221  "Unrecognized option %s", key.c_str());
222  }
223  return GFTTDetector::create(maxCorners, qualityLevel, minDistance,
224  blockSize, gradientSize, useHarrisDetector, k);
225 }
226 
230 {
231  nargchk((std::distance(first, last) % 2) == 0);
232  SimpleBlobDetector::Params parameters;
233  for (; first != last; first += 2) {
234  string key((*first).toString());
235  const MxArray& val = *(first + 1);
236  if (key == "ThresholdStep")
237  parameters.thresholdStep = val.toFloat();
238  else if (key == "MinThreshold")
239  parameters.minThreshold = val.toFloat();
240  else if (key == "MaxThreshold")
241  parameters.maxThreshold = val.toFloat();
242  else if (key == "MinRepeatability")
243  parameters.minRepeatability = val.toInt();
244  else if (key == "MinDistBetweenBlobs")
245  parameters.minDistBetweenBlobs = val.toFloat();
246  else if (key == "FilterByColor")
247  parameters.filterByColor = val.toBool();
248  else if (key == "BlobColor")
249  parameters.blobColor = static_cast<uchar>(val.toInt());
250  else if (key == "FilterByArea")
251  parameters.filterByArea = val.toBool();
252  else if (key == "MinArea")
253  parameters.minArea = val.toFloat();
254  else if (key == "MaxArea")
255  parameters.maxArea = val.toFloat();
256  else if (key == "FilterByCircularity")
257  parameters.filterByCircularity = val.toBool();
258  else if (key == "MinCircularity")
259  parameters.minCircularity = val.toFloat();
260  else if (key == "MaxCircularity")
261  parameters.maxCircularity = val.toFloat();
262  else if (key == "FilterByInertia")
263  parameters.filterByInertia = val.toBool();
264  else if (key == "MinInertiaRatio")
265  parameters.minInertiaRatio = val.toFloat();
266  else if (key == "MaxInertiaRatio")
267  parameters.maxInertiaRatio = val.toFloat();
268  else if (key == "FilterByConvexity")
269  parameters.filterByConvexity = val.toBool();
270  else if (key == "MinConvexity")
271  parameters.minConvexity = val.toFloat();
272  else if (key == "MaxConvexity")
273  parameters.maxConvexity = val.toFloat();
274  else
275  mexErrMsgIdAndTxt("mexopencv:error",
276  "Unrecognized option %s", key.c_str());
277  }
278  return SimpleBlobDetector::create(parameters);
279 }
280 
284 {
285  nargchk((std::distance(first, last) % 2) == 0);
286  bool extended = false;
287  bool upright = false;
288  float threshold = 0.001f;
289  int nOctaves = 4;
290  int nOctaveLayers = 4;
291  int diffusivity = KAZE::DIFF_PM_G2;
292  for (; first != last; first += 2) {
293  string key((*first).toString());
294  const MxArray& val = *(first + 1);
295  if (key == "Extended")
296  extended = val.toBool();
297  else if (key == "Upright")
298  upright = val.toBool();
299  else if (key == "Threshold")
300  threshold = val.toFloat();
301  else if (key == "NOctaves")
302  nOctaves = val.toInt();
303  else if (key == "NOctaveLayers")
304  nOctaveLayers = val.toInt();
305  else if(key == "Diffusivity")
306  diffusivity = KAZEDiffusivityType[val.toString()];
307  else
308  mexErrMsgIdAndTxt("mexopencv:error",
309  "Unrecognized option %s", key.c_str());
310  }
311  return KAZE::create(extended, upright, threshold,
312  nOctaves, nOctaveLayers, diffusivity);
313 }
314 
318 {
319  nargchk((std::distance(first, last) % 2) == 0);
320  int descriptor_type = AKAZE::DESCRIPTOR_MLDB;
321  int descriptor_size = 0;
322  int descriptor_channels = 3;
323  float threshold = 0.001f;
324  int nOctaves = 4;
325  int nOctaveLayers = 4;
326  int diffusivity = KAZE::DIFF_PM_G2;
327  for (; first != last; first += 2) {
328  string key((*first).toString());
329  const MxArray& val = *(first + 1);
330  if (key == "DescriptorType")
331  descriptor_type = AKAZEDescriptorType[val.toString()];
332  else if (key == "DescriptorSize")
333  descriptor_size = val.toInt();
334  else if (key == "DescriptorChannels")
335  descriptor_channels = val.toInt();
336  else if (key == "Threshold")
337  threshold = val.toFloat();
338  else if (key == "NOctaves")
339  nOctaves = val.toInt();
340  else if (key == "NOctaveLayers")
341  nOctaveLayers = val.toInt();
342  else if (key == "Diffusivity")
343  diffusivity = KAZEDiffusivityType[val.toString()];
344  else
345  mexErrMsgIdAndTxt("mexopencv:error",
346  "Unrecognized option %s", key.c_str());
347  }
348  return AKAZE::create(descriptor_type, descriptor_size, descriptor_channels,
349  threshold, nOctaves, nOctaveLayers, diffusivity);
350 }
351 
355 {
356  nargchk((std::distance(first, last) % 2) == 0);
357  int threshold = 10;
358  bool nonmaxSuppression = true;
360  for (; first != last; first += 2) {
361  string key((*first).toString());
362  const MxArray& val = *(first + 1);
363  if (key == "Threshold")
364  threshold = val.toInt();
365  else if (key == "NonmaxSuppression")
366  nonmaxSuppression = val.toBool();
367  else if (key == "Type")
368  type = AgastTypeMap[val.toString()];
369  else
370  mexErrMsgIdAndTxt("mexopencv:error",
371  "Unrecognized option %s", key.c_str());
372  }
373  return AgastFeatureDetector::create(threshold, nonmaxSuppression, type);
374 }
375 
376 #ifdef HAVE_OPENCV_XFEATURES2D
380 {
381  nargchk((std::distance(first, last) % 2) == 0);
382  int nfeatures = 0;
383  int nOctaveLayers = 3;
384  double contrastThreshold = 0.04;
385  double edgeThreshold = 10;
386  double sigma = 1.6;
387  for (; first != last; first += 2) {
388  string key((*first).toString());
389  const MxArray& val = *(first + 1);
390  if (key == "NFeatures")
391  nfeatures = val.toInt();
392  else if (key == "NOctaveLayers")
393  nOctaveLayers = val.toInt();
394  else if (key == "ConstrastThreshold")
395  contrastThreshold = val.toDouble();
396  else if (key == "EdgeThreshold")
397  edgeThreshold = val.toDouble();
398  else if (key == "Sigma")
399  sigma = val.toDouble();
400  else
401  mexErrMsgIdAndTxt("mexopencv:error",
402  "Unrecognized option %s", key.c_str());
403  }
404  return SIFT::create(nfeatures, nOctaveLayers, contrastThreshold,
405  edgeThreshold, sigma);
406 }
407 
411 {
412  nargchk((std::distance(first, last) % 2) == 0);
413  double hessianThreshold = 100;
414  int nOctaves = 4;
415  int nOctaveLayers = 3;
416  bool extended = false;
417  bool upright = false;
418  for (; first != last; first += 2) {
419  string key((*first).toString());
420  const MxArray& val = *(first + 1);
421  if (key == "HessianThreshold")
422  hessianThreshold = val.toDouble();
423  else if (key == "NOctaves")
424  nOctaves = val.toInt();
425  else if (key == "NOctaveLayers")
426  nOctaveLayers = val.toInt();
427  else if (key == "Extended")
428  extended = val.toBool();
429  else if (key == "Upright")
430  upright = val.toBool();
431  else
432  mexErrMsgIdAndTxt("mexopencv:error",
433  "Unrecognized option %s", key.c_str());
434  }
435  return SURF::create(hessianThreshold, nOctaves, nOctaveLayers,
436  extended, upright);
437 }
438 
442 {
443  nargchk((std::distance(first, last) % 2) == 0);
444  bool orientationNormalized = true;
445  bool scaleNormalized = true;
446  float patternScale = 22.0f;
447  int nOctaves = 4;
448  vector<int> selectedPairs;
449  for (; first != last; first += 2) {
450  string key((*first).toString());
451  const MxArray& val = *(first + 1);
452  if (key == "OrientationNormalized")
453  orientationNormalized = val.toBool();
454  else if (key == "ScaleNormalized")
455  scaleNormalized = val.toBool();
456  else if (key == "PatternScale")
457  patternScale = val.toFloat();
458  else if (key == "NOctaves")
459  nOctaves = val.toInt();
460  else if (key == "SelectedPairs")
461  selectedPairs = val.toVector<int>();
462  else
463  mexErrMsgIdAndTxt("mexopencv:error",
464  "Unrecognized option %s", key.c_str());
465  }
466  return FREAK::create(orientationNormalized, scaleNormalized, patternScale,
467  nOctaves, selectedPairs);
468 }
469 
473 {
474  nargchk((std::distance(first, last) % 2) == 0);
475  int maxSize = 45;
476  int responseThreshold = 30;
477  int lineThresholdProjected = 10;
478  int lineThresholdBinarized = 8;
479  int suppressNonmaxSize = 5;
480  for (; first != last; first += 2) {
481  string key((*first).toString());
482  const MxArray& val = *(first + 1);
483  if (key == "MaxSize")
484  maxSize = val.toInt();
485  else if (key == "ResponseThreshold")
486  responseThreshold = val.toInt();
487  else if (key == "LineThresholdProjected")
488  lineThresholdProjected = val.toInt();
489  else if (key == "LineThresholdBinarized")
490  lineThresholdBinarized = val.toInt();
491  else if (key == "SuppressNonmaxSize")
492  suppressNonmaxSize = val.toInt();
493  else
494  mexErrMsgIdAndTxt("mexopencv:error",
495  "Unrecognized option %s", key.c_str());
496  }
497  return StarDetector::create(maxSize, responseThreshold,
498  lineThresholdProjected, lineThresholdBinarized, suppressNonmaxSize);
499 }
500 
504 {
505  nargchk((std::distance(first, last) % 2) == 0);
506  int bytes = 32;
507  bool use_orientation = false;
508  for (; first != last; first += 2) {
509  string key((*first).toString());
510  const MxArray& val = *(first + 1);
511  if (key == "Bytes")
512  bytes = val.toInt();
513  else if (key == "UseOrientation")
514  use_orientation = val.toBool();
515  else
516  mexErrMsgIdAndTxt("mexopencv:error",
517  "Unrecognized option %s", key.c_str());
518  }
519  return BriefDescriptorExtractor::create(bytes, use_orientation);
520 }
521 
525 {
526  nargchk((std::distance(first, last) % 2) == 0);
527  int lucid_kernel = 1;
528  int blur_kernel = 2;
529  for (; first != last; first += 2) {
530  string key((*first).toString());
531  const MxArray& val = *(first + 1);
532  if (key == "LucidKernel")
533  lucid_kernel = val.toInt();
534  else if (key == "BlurKernel")
535  blur_kernel = val.toInt();
536  else
537  mexErrMsgIdAndTxt("mexopencv:error",
538  "Unrecognized option %s", key.c_str());
539  }
540  return LUCID::create(lucid_kernel, blur_kernel);
541 }
542 
546 {
547  nargchk((std::distance(first, last) % 2) == 0);
548  int bytes = 32;
549  bool rotationInvariance = true;
550  int half_ssd_size = 3;
551  double sigma = 2.0;
552  for (; first != last; first += 2) {
553  string key(first->toString());
554  const MxArray& val = *(first + 1);
555  if (key == "Bytes")
556  bytes = val.toInt();
557  else if (key == "RotationInvariance")
558  rotationInvariance = val.toBool();
559  else if (key == "HalfSize")
560  half_ssd_size = val.toInt();
561  else if (key == "Sigma")
562  sigma = val.toDouble();
563  else
564  mexErrMsgIdAndTxt("mexopencv:error",
565  "Unrecognized option %s", key.c_str());
566  }
567  return LATCH::create(bytes, rotationInvariance, half_ssd_size, sigma);
568 }
569 
573 {
574  nargchk((std::distance(first, last) % 2) == 0);
575  float radius = 15;
576  int q_radius = 3;
577  int q_theta = 8;
578  int q_hist = 8;
579  int norm = DAISY::NRM_NONE;
580  Mat H;
581  bool interpolation = true;
582  bool use_orientation = false;
583  for (; first != last; first += 2) {
584  string key(first->toString());
585  const MxArray& val = *(first + 1);
586  if (key == "Radius")
587  radius = val.toFloat();
588  else if (key == "RadiusQuant")
589  q_radius = val.toInt();
590  else if (key == "AngleQuant")
591  q_theta = val.toInt();
592  else if (key == "GradOrientationsQuant")
593  q_hist = val.toInt();
594  else if (key == "Normalization")
595  norm = DAISYNormType[val.toString()];
596  else if (key == "H")
597  H = val.toMat();
598  else if (key == "Interpolation")
599  interpolation = val.toBool();
600  else if (key == "UseOrientation")
601  use_orientation = val.toBool();
602  else
603  mexErrMsgIdAndTxt("mexopencv:error",
604  "Unrecognized option %s", key.c_str());
605  }
606  return DAISY::create(radius, q_radius, q_theta, q_hist,
607  norm, H, interpolation, use_orientation);
608 }
609 
613 {
614  nargchk((std::distance(first, last) % 2) == 0);
615  int patch_radius = 3;
616  int search_area_radius = 5;
617  int nms_radius = 5;
618  int nms_scale_radius = 0;
619  float th_saliency = 250.0f;
620  int kNN = 4;
621  float scale_factor = 1.25f;
622  int n_scales = -1;
623  bool compute_orientation = false;
624  for (; first != last; first += 2) {
625  string key((*first).toString());
626  const MxArray& val = *(first + 1);
627  if (key == "PatchRadius")
628  patch_radius = val.toInt();
629  else if (key == "SearchAreaRadius")
630  search_area_radius = val.toInt();
631  else if (key == "NMSRadius")
632  nms_radius = val.toInt();
633  else if (key == "NMSScaleRadius")
634  nms_scale_radius = val.toInt();
635  else if (key == "ThSaliency")
636  th_saliency = val.toFloat();
637  else if (key == "KNN")
638  kNN = val.toInt();
639  else if (key == "ScaleFactor")
640  scale_factor = val.toFloat();
641  else if (key == "NScales")
642  n_scales = val.toInt();
643  else if (key == "ComputeOrientation")
644  compute_orientation = val.toBool();
645  else
646  mexErrMsgIdAndTxt("mexopencv:error",
647  "Unrecognized option %s", key.c_str());
648  }
649  return MSDDetector::create(patch_radius, search_area_radius, nms_radius,
650  nms_scale_radius, th_saliency, kNN, scale_factor, n_scales,
651  compute_orientation);
652 }
653 
657 {
658  nargchk((std::distance(first, last) % 2) == 0);
659  int desc = VGG::VGG_120;
660  float isigma = 1.4f;
661  bool img_normalize = true;
662  bool use_scale_orientation = true;
663  float scale_factor = 6.25f;
664  bool dsc_normalize = false;
665  for (; first != last; first += 2) {
666  string key(first->toString());
667  const MxArray& val = *(first + 1);
668  if (key == "Desc")
669  desc = VGGDescType[val.toString()];
670  else if (key == "Sigma")
671  isigma = val.toFloat();
672  else if (key == "ImgNormalize")
673  img_normalize = val.toBool();
674  else if (key == "UseScaleOrientation")
675  use_scale_orientation = val.toBool();
676  else if (key == "ScaleFactor")
677  scale_factor = val.toFloat();
678  else if (key == "DescNormalize")
679  dsc_normalize = val.toBool();
680  else
681  mexErrMsgIdAndTxt("mexopencv:error",
682  "Unrecognized option %s", key.c_str());
683  }
684  return VGG::create(desc, isigma, img_normalize, use_scale_orientation,
685  scale_factor, dsc_normalize);
686 }
687 
691 {
692  nargchk((std::distance(first, last) % 2) == 0);
693  int desc = BoostDesc::BINBOOST_256;
694  bool use_scale_orientation = true;
695  float scale_factor = 6.25f;
696  for (; first != last; first += 2) {
697  string key(first->toString());
698  const MxArray& val = *(first + 1);
699  if (key == "Desc")
700  desc = BoostDescType[val.toString()];
701  else if (key == "UseScaleOrientation")
702  use_scale_orientation = val.toBool();
703  else if (key == "ScaleFactor")
704  scale_factor = val.toFloat();
705  else
706  mexErrMsgIdAndTxt("mexopencv:error",
707  "Unrecognized option %s", key.c_str());
708  }
709  return BoostDesc::create(desc, use_scale_orientation, scale_factor);
710 }
711 
715 {
716  nargchk((std::distance(first, last) % 2) == 0);
717  int numOctaves = 6;
718  float corn_thresh = 0.01f;
719  float DOG_thresh = 0.01f;
720  int maxCorners = 5000;
721  int num_layers = 4;
722  for (; first != last; first += 2) {
723  string key((*first).toString());
724  const MxArray& val = *(first + 1);
725  if (key == "NumOctaves")
726  numOctaves = val.toInt();
727  else if (key == "CornThresh")
728  corn_thresh = val.toFloat();
729  else if (key == "DOGThresh")
730  DOG_thresh = val.toFloat();
731  else if (key == "MaxCorners")
732  maxCorners = val.toInt();
733  else if (key == "NumLayers")
734  num_layers = val.toInt();
735  else
736  mexErrMsgIdAndTxt("mexopencv:error",
737  "Unrecognized option %s", key.c_str());
738  }
740  numOctaves, corn_thresh, DOG_thresh, maxCorners, num_layers);
741 }
742 #endif
743 
745  const string& type,
748 {
750  if (type == "BRISK")
751  p = createBRISK(first, last);
752  else if (type == "ORB")
753  p = createORB(first, last);
754  else if (type == "MSER")
755  p = createMSER(first, last);
756  else if (type == "FastFeatureDetector")
757  p = createFastFeatureDetector(first, last);
758  else if (type == "GFTTDetector")
759  p = createGFTTDetector(first, last);
760  else if (type == "SimpleBlobDetector")
761  p = createSimpleBlobDetector(first, last);
762  else if (type == "KAZE")
763  p = createKAZE(first, last);
764  else if (type == "AKAZE")
765  p = createAKAZE(first, last);
766  else if (type == "AgastFeatureDetector")
767  p = createAgastFeatureDetector(first, last);
768 #ifdef HAVE_OPENCV_XFEATURES2D
769  else if (type == "SIFT")
770  p = createSIFT(first, last);
771  else if (type == "SURF")
772  p = createSURF(first, last);
773  else if (type == "StarDetector")
774  p = createStarDetector(first, last);
775  else if (type == "MSDDetector")
776  p = createMSDDetector(first, last);
777  else if (type == "HarrisLaplaceFeatureDetector")
778  p = createHarrisLaplaceFeatureDetector(first, last);
779 #endif
780  else
781  mexErrMsgIdAndTxt("mexopencv:error",
782  "Unrecognized detector %s", type.c_str());
783  if (p.empty())
784  mexErrMsgIdAndTxt("mexopencv:error",
785  "Failed to create FeatureDetector of type %s", type.c_str());
786  return p;
787 }
788 
790  const string& type,
793 {
795  if (type == "BRISK")
796  p = createBRISK(first, last);
797  else if (type == "ORB")
798  p = createORB(first, last);
799  else if (type == "KAZE")
800  p = createKAZE(first, last);
801  else if (type == "AKAZE")
802  p = createAKAZE(first, last);
803 #ifdef HAVE_OPENCV_XFEATURES2D
804  else if (type == "SIFT")
805  p = createSIFT(first, last);
806  else if (type == "SURF")
807  p = createSURF(first, last);
808  else if (type == "FREAK")
809  p = createFREAK(first, last);
810  else if (type == "BriefDescriptorExtractor")
811  p = createBriefDescriptorExtractor(first, last);
812  else if (type == "LUCID")
813  p = createLUCID(first, last);
814  else if (type == "LATCH")
815  p = createLATCH(first, last);
816  else if (type == "DAISY")
817  p = createDAISY(first, last);
818  else if (type == "VGG")
819  p = createVGG(first, last);
820  else if (type == "BoostDesc")
821  p = createBoostDesc(first, last);
822 #endif
823  else
824  mexErrMsgIdAndTxt("mexopencv:error",
825  "Unrecognized extractor %s", type.c_str());
826  if (p.empty())
827  mexErrMsgIdAndTxt("mexopencv:error",
828  "Failed to create DescriptorExtractor of type %s", type.c_str());
829  return p;
830 }
831 
832 
833 /**************************************************************\
834 * Descriptor Matching *
835 \**************************************************************/
836 
841  ("Gonzales", cvflann::FLANN_CENTERS_GONZALES)
842  ("KMeansPP", cvflann::FLANN_CENTERS_KMEANSPP)
843  ("Groupwise", cvflann::FLANN_CENTERS_GROUPWISE);
844 
851 {
853  vector<MxArray> rhs(m.toVector<MxArray>());
854  nargchk(!rhs.empty());
855  string type(rhs[0].toString());
856  if (type == "Linear") {
857  nargchk(rhs.size() == 1);
858  p = makePtr<flann::LinearIndexParams>();
859  }
860  else if (type == "KDTree") {
861  nargchk((rhs.size() % 2) == 1);
862  int trees = 4;
863  for (size_t i = 1; i<rhs.size(); i += 2) {
864  string key(rhs[i].toString());
865  if (key == "Trees")
866  trees = rhs[i+1].toInt();
867  else
868  mexErrMsgIdAndTxt("mexopencv:error",
869  "Unrecognized option %s", key.c_str());
870  }
871  p = makePtr<flann::KDTreeIndexParams>(trees);
872  }
873  else if (type == "KMeans") {
874  nargchk((rhs.size() % 2) == 1);
875  int branching = 32;
876  int iterations = 11;
878  float cb_index = 0.2f;
879  for (size_t i = 1; i<rhs.size(); i += 2) {
880  string key(rhs[i].toString());
881  if (key == "Branching")
882  branching = rhs[i+1].toInt();
883  else if (key == "Iterations")
884  iterations = rhs[i+1].toInt();
885  else if (key == "CentersInit")
886  centers_init = CentersInit[rhs[i+1].toString()];
887  else if (key == "CBIndex")
888  cb_index = rhs[i+1].toFloat();
889  else
890  mexErrMsgIdAndTxt("mexopencv:error",
891  "Unrecognized option %s", key.c_str());
892  }
893  p = makePtr<flann::KMeansIndexParams>(
894  branching, iterations, centers_init, cb_index);
895  }
896  else if (type == "Composite") {
897  nargchk((rhs.size() % 2) == 1);
898  int trees = 4;
899  int branching = 32;
900  int iterations = 11;
902  float cb_index = 0.2f;
903  for (size_t i = 1; i<rhs.size(); i += 2) {
904  string key(rhs[i].toString());
905  if (key == "Trees")
906  trees = rhs[i+1].toInt();
907  else if (key == "Branching")
908  branching = rhs[i+1].toInt();
909  else if (key == "Iterations")
910  iterations = rhs[i+1].toInt();
911  else if (key == "CentersInit")
912  centers_init = CentersInit[rhs[i+1].toString()];
913  else if (key == "CBIndex")
914  cb_index = rhs[i+1].toFloat();
915  else
916  mexErrMsgIdAndTxt("mexopencv:error",
917  "Unrecognized option %s", key.c_str());
918  }
919  p = makePtr<flann::CompositeIndexParams>(
920  trees, branching, iterations, centers_init, cb_index);
921  }
922  else if (type == "LSH") {
923  nargchk((rhs.size() % 2) == 1);
924  int table_number = 20;
925  int key_size = 15;
926  int multi_probe_level = 0;
927  for (size_t i = 1; i<rhs.size(); i += 2) {
928  string key(rhs[i].toString());
929  if (key == "TableNumber")
930  table_number = rhs[i+1].toInt();
931  else if (key == "KeySize")
932  key_size = rhs[i+1].toInt();
933  else if (key == "MultiProbeLevel")
934  multi_probe_level = rhs[i+1].toInt();
935  else
936  mexErrMsgIdAndTxt("mexopencv:error",
937  "Unrecognized option %s", key.c_str());
938  }
939  p = makePtr<flann::LshIndexParams>(
940  table_number, key_size, multi_probe_level);
941  }
942  else if (type == "Autotuned") {
943  nargchk((rhs.size() % 2) == 1);
944  float target_precision = 0.8f;
945  float build_weight = 0.01f;
946  float memory_weight = 0;
947  float sample_fraction = 0.1f;
948  for (size_t i = 1; i<rhs.size(); i += 2) {
949  string key(rhs[i].toString());
950  if (key == "TargetPrecision")
951  target_precision = rhs[i+1].toFloat();
952  else if (key == "BuildWeight")
953  build_weight = rhs[i+1].toFloat();
954  else if (key == "MemoryWeight")
955  memory_weight = rhs[i+1].toFloat();
956  else if (key == "SampleFraction")
957  sample_fraction = rhs[i+1].toFloat();
958  else
959  mexErrMsgIdAndTxt("mexopencv:error",
960  "Unrecognized option %s", key.c_str());
961  }
962  p = makePtr<flann::AutotunedIndexParams>(
963  target_precision, build_weight, memory_weight, sample_fraction);
964  }
965  else if (type == "Saved") {
966  nargchk(rhs.size() == 2);
967  string filename(rhs[1].toString());
968  p = makePtr<flann::SavedIndexParams>(filename);
969  }
970  else if (type == "HierarchicalClustering") {
971  nargchk((rhs.size() % 2) == 1);
972  int branching = 32;
974  int trees = 4;
975  int leaf_size = 100;
976  for (size_t i = 1; i<rhs.size(); i += 2) {
977  string key(rhs[i].toString());
978  if (key == "Branching")
979  branching = rhs[i+1].toInt();
980  else if (key == "CentersInit")
981  centers_init = CentersInit[rhs[i+1].toString()];
982  else if (key == "Trees")
983  trees = rhs[i+1].toInt();
984  else if (key == "LeafSize")
985  leaf_size = rhs[i+1].toInt();
986  else
987  mexErrMsgIdAndTxt("mexopencv:error",
988  "Unrecognized option %s", key.c_str());
989  }
990  p = makePtr<flann::HierarchicalClusteringIndexParams>(
991  branching, centers_init, trees, leaf_size);
992  }
993  else
994  mexErrMsgIdAndTxt("mexopencv:error",
995  "Unrecognized IndexParams type: %s", type.c_str());
996  return p;
997 }
998 
1005 {
1006  vector<MxArray> rhs(m.toVector<MxArray>());
1007  nargchk((rhs.size() % 2) == 0);
1008  int checks = 32;
1009  float eps = 0;
1010  bool sorted = true;
1011  for (size_t i = 0; i<rhs.size(); i += 2) {
1012  string key(rhs[i].toString());
1013  if (key == "Checks")
1014  checks = rhs[i+1].toInt();
1015  else if (key == "EPS")
1016  eps = rhs[i+1].toFloat();
1017  else if (key == "Sorted")
1018  sorted = rhs[i+1].toBool();
1019  else
1020  mexErrMsgIdAndTxt("mexopencv:error",
1021  "Unrecognized option %s", key.c_str());
1022  }
1023  return makePtr<flann::SearchParams>(checks, eps, sorted);
1024 }
1025 
1029 {
1030  nargchk((std::distance(first, last) % 2) == 0);
1031  Ptr<flann::IndexParams> indexParams;
1032  Ptr<flann::SearchParams> searchParams;
1033  for (; first != last; first += 2) {
1034  string key((*first).toString());
1035  const MxArray& val = *(first + 1);
1036  if (key == "Index")
1037  indexParams = toIndexParams(val);
1038  else if (key == "Search")
1039  searchParams = toSearchParams(val);
1040  else
1041  mexErrMsgIdAndTxt("mexopencv:error",
1042  "Unrecognized option %s", key.c_str());
1043  }
1044  if (indexParams.empty())
1045  indexParams = makePtr<flann::KDTreeIndexParams>();
1046  if (searchParams.empty())
1047  searchParams = makePtr<flann::SearchParams>();
1048  //return FlannBasedMatcher::create();
1049  return makePtr<FlannBasedMatcher>(indexParams, searchParams);
1050 }
1051 
1055 {
1056  nargchk((std::distance(first, last) % 2) == 0);
1057  int normType = cv::NORM_L2;
1058  bool crossCheck = false;
1059  for (; first != last; first += 2) {
1060  string key((*first).toString());
1061  const MxArray& val = *(first + 1);
1062  if (key == "NormType")
1063  normType = NormType[val.toString()];
1064  else if (key == "CrossCheck")
1065  crossCheck = val.toBool();
1066  else
1067  mexErrMsgIdAndTxt("mexopencv:error",
1068  "Unrecognized option %s", key.c_str());
1069  }
1070  return BFMatcher::create(normType, crossCheck);
1071 }
1072 
1074  const string& type,
1077 {
1079  if (std::distance(first, last) > 0) {
1080  if (type == "FlannBasedMatcher")
1081  p = createFlannBasedMatcher(first, last);
1082  else if (type == "BFMatcher")
1083  p = createBFMatcher(first, last);
1084  else
1085  mexErrMsgIdAndTxt("mexopencv:error",
1086  "Unrecognized matcher %s", type.c_str());
1087  }
1088  else
1090  if (p.empty())
1091  mexErrMsgIdAndTxt("mexopencv:error",
1092  "Failed to create DescriptorMatcher of type %s", type.c_str());
1093  return p;
1094 }
static Ptr< FREAK > create(bool orientationNormalized=true, bool scaleNormalized=true, float patternScale=22.0f, int nOctaves=4, const std::vector< int > &selectedPairs=std::vector< int >())
static double norm(const Matx< _Tp, m, n > &M)
Ptr< GFTTDetector > createGFTTDetector(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of GFTTDetector using options in arguments.
const ConstMap< std::string, int > AgastTypeMap
AGAST neighborhood types.
const ConstMap< std::string, int > KAZEDiffusivityType
KAZE Diffusivity type.
cv::Ptr< cv::xfeatures2d::LATCH > createLATCH(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of LATCH using options in arguments.
int toInt() const
Convert MxArray to int.
Definition: MxArray.cpp:489
T empty(T... args)
const ConstMap< string, cvflann::flann_centers_init_t > CentersInit
IndexParams centers initialization methods.
static Ptr< MSDDetector > create(int m_patch_radius=3, int m_search_area_radius=5, int m_nms_radius=5, int m_nms_scale_radius=0, float m_th_saliency=250.0f, int m_kNN=4, float m_scale_factor=1.25f, int m_n_scales=-1, bool m_compute_orientation=false)
T distance(T... args)
static Ptr< BriefDescriptorExtractor > create(int bytes=32, bool use_orientation=false)
FLANN_CENTERS_GONZALES
Ptr< FastFeatureDetector > createFastFeatureDetector(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FastFeatureDetector using options in arguments.
Ptr< BRISK > createBRISK(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BRISK using options in arguments.
Ptr< flann::SearchParams > toSearchParams(const MxArray &m)
Convert MxArray to FLANN search parameters.
cv::Ptr< cv::xfeatures2d::FREAK > createFREAK(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of FREAK using options in arguments.
const ConstMap< std::string, int > DAISYNormType
DAISY normalization types.
const ConstMap< std::string, int > AKAZEDescriptorType
AKAZE descriptor type.
cv::Ptr< cv::xfeatures2d::MSDDetector > createMSDDetector(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of MSDDetector using options in arguments.
cv::Ptr< cv::xfeatures2d::SURF > createSURF(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of SURF using options in arguments.
static Ptr< GFTTDetector > create(int maxCorners=1000, double qualityLevel=0.01, double minDistance=1, int blockSize=3, bool useHarrisDetector=false, double k=0.04)
static Ptr< VGG > create(int desc=VGG::VGG_120, float isigma=1.4f, bool img_normalize=true, bool use_scale_orientation=true, float scale_factor=6.25f, bool dsc_normalize=false)
Ptr< DescriptorMatcher > createDescriptorMatcher(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Factory function for DescriptorMatcher creation.
static Ptr< LATCH > create(int bytes=32, bool rotationInvariance=true, int half_ssd_size=3, double sigma=2.0)
Ptr< AgastFeatureDetector > createAgastFeatureDetector(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of AgastFeatureDetector using options in arguments.
Ptr< AKAZE > createAKAZE(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of AKAZE using options in arguments.
Ptr< FlannBasedMatcher > createFlannBasedMatcher(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FlannBasedMatcher using options in arguments.
static Ptr< FastFeatureDetector > create(int threshold=10, bool nonmaxSuppression=true, int type=FastFeatureDetector::TYPE_9_16)
Ptr< FeatureDetector > createFeatureDetector(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Factory function for FeatureDetector creation.
static Ptr< ORB > create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20)
STL class.
static Ptr< SimpleBlobDetector > create(const SimpleBlobDetector::Params &parameters=SimpleBlobDetector::Params())
static Ptr< SIFT > create(int nfeatures=0, int nOctaveLayers=3, double contrastThreshold=0.04, double edgeThreshold=10, double sigma=1.6)
cv::Ptr< cv::xfeatures2d::DAISY > createDAISY(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of DAISY using options in arguments.
static Ptr< BFMatcher > create(int normType=NORM_L2, bool crossCheck=false)
static Ptr< KAZE > create(bool extended=false, bool upright=false, float threshold=0.001f, int nOctaves=4, int nOctaveLayers=4, int diffusivity=KAZE::DIFF_PM_G2)
Ptr< flann::IndexParams > toIndexParams(const MxArray &m)
Convert MxArray to FLANN index parameters.
Ptr< KAZE > createKAZE(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of KAZE using options in arguments.
Ptr< DescriptorExtractor > createDescriptorExtractor(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Factory function for DescriptorExtractor creation.
const ConstMap< std::string, int > VGGDescType
VGG descriptor types.
bool toBool() const
Convert MxArray to bool.
Definition: MxArray.cpp:510
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
float toFloat() const
Convert MxArray to float.
Definition: MxArray.cpp:503
unsigned char uchar
static Ptr< MSER > create(int _delta=5, int _min_area=60, int _max_area=14400, double _max_variation=0.25, double _min_diversity=.2, int _max_evolution=200, double _area_threshold=1.01, double _min_margin=0.003, int _edge_blur_size=5)
flann_centers_init_t
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
Common definitions for the features2d and xfeatures2d modules.
const ConstMap< std::string, int > BoostDescType
BoostDesc descriptor types.
static Ptr< HarrisLaplaceFeatureDetector > create(int numOctaves=6, float corn_thresh=0.01f, float DOG_thresh=0.01f, int maxCorners=5000, int num_layers=4)
cv::Ptr< cv::xfeatures2d::SIFT > createSIFT(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of SIFT using options in arguments.
T size(T... args)
cv::Ptr< cv::xfeatures2d::StarDetector > createStarDetector(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of StarDetector using options in arguments.
std::vector< T > toVector() const
Convert MxArray to std::vector<T> of primitive types.
Definition: MxArray.hpp:1151
STL class.
bool empty() const
FLANN_CENTERS_GROUPWISE
cv::Ptr< cv::xfeatures2d::BriefDescriptorExtractor > createBriefDescriptorExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of BriefDescriptorExtractor using options in arguments.
T c_str(T... args)
Ptr< ORB > createORB(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ORB using options in arguments.
static Ptr< LUCID > create(const int lucid_kernel=1, const int blur_kernel=2)
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
static Ptr< StarDetector > create(int maxSize=45, int responseThreshold=30, int lineThresholdProjected=10, int lineThresholdBinarized=8, int suppressNonmaxSize=5)
double toDouble() const
Convert MxArray to double.
Definition: MxArray.cpp:496
cv::Ptr< cv::xfeatures2d::VGG > createVGG(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of VGG using options in arguments.
static softfloat eps()
static Ptr< DAISY > create(float radius=15, int q_radius=3, int q_theta=8, int q_hist=8, int norm=DAISY::NRM_NONE, InputArray H=noArray(), bool interpolation=true, bool use_orientation=false)
Ptr< SimpleBlobDetector > createSimpleBlobDetector(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of SimpleBlobDetector using options in arguments.
FLANN_CENTERS_RANDOM
Ptr< BFMatcher > createBFMatcher(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BFMatcher using options in arguments.
static Ptr< AKAZE > create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB, int descriptor_size=0, int descriptor_channels=3, float threshold=0.001f, int nOctaves=4, int nOctaveLayers=4, int diffusivity=KAZE::DIFF_PM_G2)
Ptr< MSER > createMSER(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MSER using options in arguments.
static Ptr< BoostDesc > create(int desc=BoostDesc::BINBOOST_256, bool use_scale_orientation=true, float scale_factor=6.25f)
cv::Ptr< cv::xfeatures2d::LUCID > createLUCID(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of LUCID using options in arguments.
int type() const
static Ptr< BRISK > create(int thresh=30, int octaves=3, float patternScale=1.0f)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Ptr< cv::xfeatures2d::HarrisLaplaceFeatureDetector > createHarrisLaplaceFeatureDetector(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of HarrisLaplaceFeatureDetector using options in arguments.
const ConstMap< std::string, int > NormType
Norm type map for option processing.
Definition: mexopencv.hpp:150
cv::Ptr< cv::xfeatures2d::BoostDesc > createBoostDesc(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of BoostDesc using options in arguments.
static Ptr< SURF > create(double hessianThreshold=100, int nOctaves=4, int nOctaveLayers=3, bool extended=false, bool upright=false)
FLANN_CENTERS_KMEANSPP
const ConstMap< std::string, int > FASTTypeMap
FAST types.
static Ptr< AgastFeatureDetector > create(int threshold=10, bool nonmaxSuppression=true, int type=AgastFeatureDetector::OAST_9_16)
static Ptr< DescriptorMatcher > create(const String &descriptorMatcherType)
const ConstMap< std::string, int > ORBScoreType
ORB score types.