mexopencv  3.4.1
MEX interface for OpenCV library
mexopencv_stitching.cpp
Go to the documentation of this file.
1 
9 #include <typeinfo>
10 using std::vector;
11 using std::string;
12 using namespace cv;
13 using namespace cv::detail;
14 
15 
16 // ==================== XXX ====================
17 
20  ("PM_G1", cv::KAZE::DIFF_PM_G1)
21  ("PM_G2", cv::KAZE::DIFF_PM_G2)
22  ("WEICKERT", cv::KAZE::DIFF_WEICKERT)
23  ("CHARBONNIER", cv::KAZE::DIFF_CHARBONNIER);
24 
27  ("KAZEUpright", cv::AKAZE::DESCRIPTOR_KAZE_UPRIGHT)
29  ("MLDBUpright", cv::AKAZE::DESCRIPTOR_MLDB_UPRIGHT)
31 
32 
33 // ==================== XXX ====================
34 
36 {
37  ImageFeatures feat;
38  feat.img_idx = arr.at("img_idx", idx).toInt();
39  feat.img_size = arr.at("img_size", idx).toSize();
40  feat.keypoints = arr.at("keypoints", idx).toVector<KeyPoint>();
41  if (arr.isField("descriptors")) {
42  arr.at("descriptors", idx).toMat().copyTo(feat.descriptors);
43  }
44  return feat;
45 }
46 
48 {
49  MatchesInfo matches_info;
50  matches_info.src_img_idx = arr.at("src_img_idx", idx).toInt();
51  matches_info.dst_img_idx = arr.at("dst_img_idx", idx).toInt();
52  matches_info.matches = arr.at("matches", idx).toVector<DMatch>();
53  matches_info.inliers_mask = arr.at("inliers_mask", idx).toVector<uchar>();
54  matches_info.num_inliers = arr.at("num_inliers", idx).toInt();
55  matches_info.H = arr.at("H", idx).toMat();
56  matches_info.confidence = arr.at("confidence", idx).toDouble();
57  return matches_info;
58 }
59 
61 {
62  CameraParams params;
63  params.aspect = arr.at("aspect", idx).toDouble();
64  params.focal = arr.at("focal", idx).toDouble();
65  params.ppx = arr.at("ppx", idx).toDouble();
66  params.ppy = arr.at("ppy", idx).toDouble();
67  params.R = arr.at("R", idx).toMat(); // CV_64F, CV_32F
68  params.t = arr.at("t", idx).toMat(); // CV_64F, CV_32F
69  return params;
70 }
71 
73 {
74  const mwSize n = arr.numel();
76  v.reserve(n);
77  if (arr.isCell())
78  for (mwIndex i = 0; i < n; ++i)
79  v.push_back(MxArrayToImageFeatures(arr.at<MxArray>(i)));
80  else if (arr.isStruct())
81  for (mwIndex i = 0; i < n; ++i)
82  v.push_back(MxArrayToImageFeatures(arr, i));
83  else
84  mexErrMsgIdAndTxt("mexopencv:error",
85  "MxArray unable to convert to vector<cv::detail::ImageFeatures>");
86  return v;
87 }
88 
90 {
91  const mwSize n = arr.numel();
93  v.reserve(n);
94  if (arr.isCell())
95  for (mwIndex i = 0; i < n; ++i)
96  v.push_back(MxArrayToMatchesInfo(arr.at<MxArray>(i)));
97  else if (arr.isStruct())
98  for (mwIndex i = 0; i < n; ++i)
99  v.push_back(MxArrayToMatchesInfo(arr, i));
100  else
101  mexErrMsgIdAndTxt("mexopencv:error",
102  "MxArray unable to convert to vector<cv::detail::MatchesInfo>");
103  return v;
104 }
105 
107 {
108  const mwSize n = arr.numel();
110  v.reserve(n);
111  if (arr.isCell())
112  for (mwIndex i = 0; i < n; ++i)
113  v.push_back(MxArrayToCameraParams(arr.at<MxArray>(i)));
114  else if (arr.isStruct())
115  for (mwIndex i = 0; i < n; ++i)
116  v.push_back(MxArrayToCameraParams(arr, i));
117  else
118  mexErrMsgIdAndTxt("mexopencv:error",
119  "MxArray unable to convert to vector<cv::detail::CameraParams>");
120  return v;
121 }
122 
124 {
125  const char *fields[] = {"img_idx", "img_size", "keypoints", "descriptors"};
126  MxArray s = MxArray::Struct(fields, 4);
127  s.set("img_idx", feat.img_idx);
128  s.set("img_size", feat.img_size);
129  s.set("keypoints", feat.keypoints);
130  s.set("descriptors", feat.descriptors.getMat(ACCESS_READ));
131  return s;
132 }
133 
135 {
136  const char *fields[] = {"img_idx", "img_size", "keypoints", "descriptors"};
137  MxArray s = MxArray::Struct(fields, 4, 1, features.size());
138  for (mwIndex i = 0; i < features.size(); ++i) {
139  s.set("img_idx", features[i].img_idx, i);
140  s.set("img_size", features[i].img_size, i);
141  s.set("keypoints", features[i].keypoints, i);
142  s.set("descriptors", features[i].descriptors.getMat(ACCESS_READ), i);
143  }
144  return s;
145 }
146 
147 MxArray toStruct(const MatchesInfo &matches_info)
148 {
149  const char *fields[] = {"src_img_idx", "dst_img_idx", "matches",
150  "inliers_mask", "num_inliers", "H", "confidence"};
151  MxArray s = MxArray::Struct(fields, 7);
152  s.set("src_img_idx", matches_info.src_img_idx);
153  s.set("dst_img_idx", matches_info.dst_img_idx);
154  s.set("matches", matches_info.matches);
155  s.set("inliers_mask", matches_info.inliers_mask);
156  s.set("num_inliers", matches_info.num_inliers);
157  s.set("H", matches_info.H);
158  s.set("confidence", matches_info.confidence);
159  return s;
160 }
161 
162 MxArray toStruct(const vector<MatchesInfo> &pairwise_matches)
163 {
164  const char *fields[] = {"src_img_idx", "dst_img_idx", "matches",
165  "inliers_mask", "num_inliers", "H", "confidence"};
166  MxArray s = MxArray::Struct(fields, 7, 1, pairwise_matches.size());
167  for (mwIndex i = 0; i < pairwise_matches.size(); ++i) {
168  s.set("src_img_idx", pairwise_matches[i].src_img_idx, i);
169  s.set("dst_img_idx", pairwise_matches[i].dst_img_idx, i);
170  s.set("matches", pairwise_matches[i].matches, i);
171  s.set("inliers_mask", pairwise_matches[i].inliers_mask, i);
172  s.set("num_inliers", pairwise_matches[i].num_inliers, i);
173  s.set("H", pairwise_matches[i].H, i);
174  s.set("confidence", pairwise_matches[i].confidence, i);
175  }
176  return s;
177 }
178 
180 {
181  const char *fields[] = {"aspect", "focal", "ppx", "ppy", "R", "t", "K"};
182  MxArray s = MxArray::Struct(fields, 7);
183  s.set("aspect", params.aspect);
184  s.set("focal", params.focal);
185  s.set("ppx", params.ppx);
186  s.set("ppy", params.ppy);
187  s.set("R", params.R);
188  s.set("t", params.t);
189  s.set("K", params.K());
190  return s;
191 }
192 
194 {
195  const char *fields[] = {"aspect", "focal", "ppx", "ppy", "R", "t", "K"};
196  MxArray s = MxArray::Struct(fields, 7, 1, cameras.size());
197  for (mwIndex i = 0; i < cameras.size(); ++i) {
198  s.set("aspect", cameras[i].aspect, i);
199  s.set("focal", cameras[i].focal, i);
200  s.set("ppx", cameras[i].ppx, i);
201  s.set("ppy", cameras[i].ppy, i);
202  s.set("R", cameras[i].R, i);
203  s.set("t", cameras[i].t, i);
204  s.set("K", cameras[i].K(), i);
205  }
206  return s;
207 }
208 
209 
210 // ==================== XXX ====================
211 
213 {
215  if (!p.empty()) {
216  s.set("TypeId", string(typeid(*p).name()));
217  //s.set("isThreadSafe", p->isThreadSafe());
218  }
219  return s;
220 }
221 
223 {
225  if (!p.empty()) {
226  s.set("TypeId", string(typeid(*p).name()));
227  s.set("isThreadSafe", p->isThreadSafe());
228  }
229  return s;
230 }
231 
233 {
235  if (!p.empty()) {
236  s.set("TypeId", string(typeid(*p).name()));
237  }
238  return s;
239 }
240 
242 {
244  if (!p.empty()) {
245  s.set("TypeId", string(typeid(*p).name()));
246  s.set("ConfThresh", p->confThresh());
247  s.set("RefinementMask", p->refinementMask());
248  s.set("TermCriteria", p->termCriteria());
249  }
250  return s;
251 }
252 
254 {
256  if (!p.empty()) {
257  s.set("TypeId", string(typeid(*p).name()));
258  }
259  return s;
260 }
261 
263 {
265  if (!p.empty()) {
266  s.set("TypeId", string(typeid(*p).name()));
267  }
268  return s;
269 }
270 
272 {
274  if (!p.empty()) {
275  s.set("TypeId", string(typeid(*p).name()));
276  {
278  if (!pp.empty())
279  s.set("CostFunction", pp->costFunction());
280  }
281  }
282  return s;
283 }
284 
286 {
288  if (!p.empty()) {
289  s.set("TypeId", string(typeid(*p).name()));
290  {
292  if (!pp.empty())
293  s.set("Sharpness", pp->sharpness());
294  }
295  {
297  if (!pp.empty())
298  s.set("NumBands", pp->numBands());
299  }
300  }
301  return s;
302 }
303 
304 
305 // ==================== XXX ====================
306 
310 {
311  ptrdiff_t len = std::distance(first, last);
312  nargchk((len%2)==0);
313  Size grid_size(3,1);
314  int nfeatures = 1500;
315  float scaleFactor = 1.3f;
316  int nlevels = 5;
317  for (; first != last; first += 2) {
318  string key(first->toString());
319  const MxArray& val = *(first + 1);
320  if (key == "GridSize")
321  grid_size = val.toSize();
322  else if (key == "NFeatures")
323  nfeatures = val.toInt();
324  else if (key == "ScaleFactor")
325  scaleFactor = val.toFloat();
326  else if (key == "NLevels")
327  nlevels = val.toInt();
328  else
329  mexErrMsgIdAndTxt("mexopencv:error",
330  "Unrecognized option %s", key.c_str());
331  }
332  return makePtr<OrbFeaturesFinder>(grid_size, nfeatures, scaleFactor, nlevels);
333 }
334 
338 {
339  ptrdiff_t len = std::distance(first, last);
340  nargchk((len%2)==0);
341  int descriptor_type = cv::AKAZE::DESCRIPTOR_MLDB;
342  int descriptor_size = 0;
343  int descriptor_channels = 3;
344  float threshold = 0.001f;
345  int nOctaves = 4;
346  int nOctaveLayers = 4;
347  int diffusivity = cv::KAZE::DIFF_PM_G2;
348  for (; first != last; first += 2) {
349  string key(first->toString());
350  const MxArray& val = *(first + 1);
351  if (key == "DescriptorType")
352  descriptor_type = AKAZEDescriptorType[val.toString()];
353  else if (key == "DescriptorSize")
354  descriptor_size = val.toInt();
355  else if (key == "DescriptorChannels")
356  descriptor_channels = val.toInt();
357  else if (key == "Threshold")
358  threshold = val.toFloat();
359  else if (key == "NOctaves")
360  nOctaves = val.toInt();
361  else if (key == "NOctaveLayers")
362  nOctaveLayers = val.toInt();
363  else if (key == "Diffusivity")
364  diffusivity = KAZEDiffusivityType[val.toString()];
365 
366  else
367  mexErrMsgIdAndTxt("mexopencv:error",
368  "Unrecognized option %s", key.c_str());
369  }
370  return makePtr<AKAZEFeaturesFinder>(descriptor_type, descriptor_size,
371  descriptor_channels, threshold, nOctaves, nOctaveLayers, diffusivity);
372 }
373 
374 #ifdef HAVE_OPENCV_XFEATURES2D
378 {
379  ptrdiff_t len = std::distance(first, last);
380  nargchk((len%2)==0);
381  double hess_thresh = 300.0;
382  int num_octaves = 3;
383  int num_layers = 4;
384  int num_octaves_descr = 3;
385  int num_layers_descr = 4;
386  for (; first != last; first += 2) {
387  string key(first->toString());
388  const MxArray& val = *(first + 1);
389  if (key == "HessThresh")
390  hess_thresh = val.toDouble();
391  else if (key == "NumOctaves")
392  num_octaves = val.toInt();
393  else if (key == "NumLayers")
394  num_layers = val.toInt();
395  else if (key == "NumOctaveDescr")
396  num_octaves_descr = val.toInt();
397  else if (key == "NumLayersDesc")
398  num_layers_descr = val.toInt();
399  else
400  mexErrMsgIdAndTxt("mexopencv:error",
401  "Unrecognized option %s", key.c_str());
402  }
403  return makePtr<SurfFeaturesFinder>(hess_thresh, num_octaves, num_layers,
404  num_octaves_descr, num_layers_descr);
405 }
406 #endif
407 
409  const string& type,
412 {
414  if (type == "OrbFeaturesFinder")
415  p = createOrbFeaturesFinder(first, last);
416  else if (type == "AKAZEFeaturesFinder")
417  p = createAKAZEFeaturesFinder(first, last);
418 #ifdef HAVE_OPENCV_XFEATURES2D
419  else if (type == "SurfFeaturesFinder")
420  p = createSurfFeaturesFinder(first, last);
421 #if 0
422  //TODO: CUDA
423  else if (type == "SurfFeaturesFinderGpu")
424  p = createSurfFeaturesFinderGpu(first, last);
425 #endif
426 #endif
427  else
428  mexErrMsgIdAndTxt("mexopencv:error",
429  "Unrecognized features finder %s", type.c_str());
430  if (p.empty())
431  mexErrMsgIdAndTxt("mexopencv:error",
432  "Failed to create FeaturesFinder");
433  return p;
434 }
435 
439 {
440  ptrdiff_t len = std::distance(first, last);
441  nargchk((len%2)==0);
442  bool try_use_gpu = false;
443  float match_conf = 0.3f;
444  int num_matches_thresh1 = 6;
445  int num_matches_thresh2 = 6;
446  for (; first != last; first += 2) {
447  string key(first->toString());
448  const MxArray& val = *(first + 1);
449  if (key == "TryUseGPU")
450  try_use_gpu = val.toBool();
451  else if (key == "MatchConf")
452  match_conf = val.toFloat();
453  else if (key == "NumMatchesThresh1")
454  num_matches_thresh1 = val.toInt();
455  else if (key == "NumMatchesThresh2")
456  num_matches_thresh2 = val.toInt();
457  else
458  mexErrMsgIdAndTxt("mexopencv:error",
459  "Unrecognized option %s", key.c_str());
460  }
461  return makePtr<BestOf2NearestMatcher>(try_use_gpu,
462  match_conf, num_matches_thresh1, num_matches_thresh2);
463 }
464 
468 {
469  ptrdiff_t len = std::distance(first, last);
470  nargchk((len%2)==0);
471  int range_width = 5;
472  bool try_use_gpu = false;
473  float match_conf = 0.3f;
474  int num_matches_thresh1 = 6;
475  int num_matches_thresh2 = 6;
476  for (; first != last; first += 2) {
477  string key(first->toString());
478  const MxArray& val = *(first + 1);
479  if (key == "RangeWidth")
480  range_width = val.toInt();
481  else if (key == "TryUseGPU")
482  try_use_gpu = val.toBool();
483  else if (key == "MatchConf")
484  match_conf = val.toFloat();
485  else if (key == "NumMatchesThresh1")
486  num_matches_thresh1 = val.toInt();
487  else if (key == "NumMatchesThresh2")
488  num_matches_thresh2 = val.toInt();
489  else
490  mexErrMsgIdAndTxt("mexopencv:error",
491  "Unrecognized option %s", key.c_str());
492  }
493  return makePtr<BestOf2NearestRangeMatcher>(range_width, try_use_gpu,
494  match_conf, num_matches_thresh1, num_matches_thresh2);
495 }
496 
500 {
501  ptrdiff_t len = std::distance(first, last);
502  nargchk((len%2)==0);
503  bool full_affine = false;
504  bool try_use_gpu = false;
505  float match_conf = 0.3f;
506  int num_matches_thresh1 = 6;
507  for (; first != last; first += 2) {
508  string key(first->toString());
509  const MxArray& val = *(first + 1);
510  if (key == "FullAffine")
511  full_affine = val.toBool();
512  else if (key == "TryUseGPU")
513  try_use_gpu = val.toBool();
514  else if (key == "MatchConf")
515  match_conf = val.toFloat();
516  else if (key == "NumMatchesThresh1")
517  num_matches_thresh1 = val.toInt();
518  else
519  mexErrMsgIdAndTxt("mexopencv:error",
520  "Unrecognized option %s", key.c_str());
521  }
522  return makePtr<AffineBestOf2NearestMatcher>(full_affine, try_use_gpu,
523  match_conf, num_matches_thresh1);
524 }
525 
527  const string& type,
530 {
532  if (type == "BestOf2NearestMatcher")
533  p = createBestOf2NearestMatcher(first, last);
534  else if (type == "BestOf2NearestRangeMatcher")
535  p = createBestOf2NearestRangeMatcher(first, last);
536  else if (type == "AffineBestOf2NearestMatcher")
537  p = createAffineBestOf2NearestMatcher(first, last);
538  else
539  mexErrMsgIdAndTxt("mexopencv:error",
540  "Unrecognized features matcher %s", type.c_str());
541  if (p.empty())
542  mexErrMsgIdAndTxt("mexopencv:error",
543  "Failed to create FeaturesMatcher");
544  return p;
545 }
546 
550 {
551  ptrdiff_t len = std::distance(first, last);
552  nargchk((len%2)==0);
553  bool is_focals_estimated = false;
554  for (; first != last; first += 2) {
555  string key(first->toString());
556  const MxArray& val = *(first + 1);
557  if (key == "IsFocalsEstimated")
558  is_focals_estimated = val.toBool();
559  else
560  mexErrMsgIdAndTxt("mexopencv:error",
561  "Unrecognized option %s", key.c_str());
562  }
563  return makePtr<HomographyBasedEstimator>(is_focals_estimated);
564 }
565 
567  const string& type,
570 {
571  ptrdiff_t len = std::distance(first, last);
572  Ptr<Estimator> p;
573  if (type == "HomographyBasedEstimator")
574  p = createHomographyBasedEstimator(first, last);
575  else if (type == "AffineBasedEstimator") {
576  nargchk(len==0);
577  p = makePtr<AffineBasedEstimator>();
578  }
579  else
580  mexErrMsgIdAndTxt("mexopencv:error",
581  "Unrecognized estimator %s", type.c_str());
582  if (p.empty())
583  mexErrMsgIdAndTxt("mexopencv:error", "Failed to create Estimator");
584  return p;
585 }
586 
588  const string& type,
591 {
592  ptrdiff_t len = std::distance(first, last);
593  nargchk((len%2)==0);
595  if (type == "NoBundleAdjuster")
596  p = makePtr<NoBundleAdjuster>();
597  else if (type == "BundleAdjusterRay")
598  p = makePtr<BundleAdjusterRay>();
599  else if (type == "BundleAdjusterReproj")
600  p = makePtr<BundleAdjusterReproj>();
601  else if (type == "BundleAdjusterAffine")
602  p = makePtr<BundleAdjusterAffine>();
603  else if (type == "BundleAdjusterAffinePartial")
604  p = makePtr<BundleAdjusterAffinePartial>();
605  else
606  mexErrMsgIdAndTxt("mexopencv:error",
607  "Unrecognized bundle adjuster %s", type.c_str());
608  if (p.empty())
609  mexErrMsgIdAndTxt("mexopencv:error",
610  "Failed to create BundleAdjusterBase");
611  for (; first != last; first += 2) {
612  string key(first->toString());
613  const MxArray& val = *(first + 1);
614  if (key == "ConfThresh")
615  p->setConfThresh(val.toDouble());
616  else if (key == "RefinementMask")
617  p->setRefinementMask(val.toMat(CV_8U));
618  else if (key == "TermCriteria")
619  p->setTermCriteria(val.toTermCriteria());
620  else
621  mexErrMsgIdAndTxt("mexopencv:error",
622  "Unrecognized option %s", key.c_str());
623  }
624  return p;
625 }
626 
630 {
631  ptrdiff_t len = std::distance(first, last);
632  nargchk((len%2)==0);
633  float A = 1;
634  float B = 1;
635  for (; first != last; first += 2) {
636  string key(first->toString());
637  const MxArray& val = *(first + 1);
638  if (key == "A")
639  A = val.toFloat();
640  else if (key == "B")
641  B = val.toFloat();
642  else
643  mexErrMsgIdAndTxt("mexopencv:error",
644  "Unrecognized option %s", key.c_str());
645  }
646  return makePtr<cv::CompressedRectilinearWarper>(A, B);
647 }
648 
652 {
653  ptrdiff_t len = std::distance(first, last);
654  nargchk((len%2)==0);
655  float A = 1;
656  float B = 1;
657  for (; first != last; first += 2) {
658  string key(first->toString());
659  const MxArray& val = *(first + 1);
660  if (key == "A")
661  A = val.toFloat();
662  else if (key == "B")
663  B = val.toFloat();
664  else
665  mexErrMsgIdAndTxt("mexopencv:error",
666  "Unrecognized option %s", key.c_str());
667  }
668  return makePtr<cv::CompressedRectilinearPortraitWarper>(A, B);
669 }
670 
674 {
675  ptrdiff_t len = std::distance(first, last);
676  nargchk((len%2)==0);
677  float A = 1;
678  float B = 1;
679  for (; first != last; first += 2) {
680  string key(first->toString());
681  const MxArray& val = *(first + 1);
682  if (key == "A")
683  A = val.toFloat();
684  else if (key == "B")
685  B = val.toFloat();
686  else
687  mexErrMsgIdAndTxt("mexopencv:error",
688  "Unrecognized option %s", key.c_str());
689  }
690  return makePtr<cv::PaniniWarper>(A, B);
691 }
692 
696 {
697  ptrdiff_t len = std::distance(first, last);
698  nargchk((len%2)==0);
699  float A = 1;
700  float B = 1;
701  for (; first != last; first += 2) {
702  string key(first->toString());
703  const MxArray& val = *(first + 1);
704  if (key == "A")
705  A = val.toFloat();
706  else if (key == "B")
707  B = val.toFloat();
708  else
709  mexErrMsgIdAndTxt("mexopencv:error",
710  "Unrecognized option %s", key.c_str());
711  }
712  return makePtr<cv::PaniniPortraitWarper>(A, B);
713 }
714 
716  const string& type,
719 {
720  ptrdiff_t len = std::distance(first, last);
722  if (type == "PlaneWarper") {
723  nargchk(len==0);
724  p = makePtr<cv::PlaneWarper>();
725  }
726  else if (type == "AffineWarper") {
727  nargchk(len==0);
728  p = makePtr<cv::AffineWarper>();
729  }
730  else if (type == "CylindricalWarper") {
731  nargchk(len==0);
732  p = makePtr<cv::CylindricalWarper>();
733  }
734  else if (type == "SphericalWarper") {
735  nargchk(len==0);
736  p = makePtr<cv::SphericalWarper>();
737  }
738 #if 0
739  //TODO: CUDA
740  else if (type == "PlaneWarperGpu")
741  p = makePtr<PlaneWarperGpu>();
742  else if (type == "CylindricalWarperGpu")
743  p = makePtr<CylindricalWarperGpu>();
744  else if (type == "SphericalWarperGpu")
745  p = makePtr<SphericalWarperGpu>();
746 #endif
747  else if (type == "FisheyeWarper") {
748  nargchk(len==0);
749  p = makePtr<cv::FisheyeWarper>();
750  }
751  else if (type == "StereographicWarper") {
752  nargchk(len==0);
753  p = makePtr<cv::StereographicWarper>();
754  }
755  else if (type == "CompressedRectilinearWarper")
756  p = createCompressedRectilinearWarper(first, last);
757  else if (type == "CompressedRectilinearPortraitWarper")
759  else if (type == "PaniniWarper")
760  p = createPaniniWarper(first, last);
761  else if (type == "PaniniPortraitWarper")
762  p = createPaniniPortraitWarper(first, last);
763  else if (type == "MercatorWarper") {
764  nargchk(len==0);
765  p = makePtr<cv::MercatorWarper>();
766  }
767  else if (type == "TransverseMercatorWarper") {
768  nargchk(len==0);
769  p = makePtr<cv::TransverseMercatorWarper>();
770  }
771  else
772  mexErrMsgIdAndTxt("mexopencv:error",
773  "Unrecognized warper creator %s", type.c_str());
774  if (p.empty())
775  mexErrMsgIdAndTxt("mexopencv:error", "Failed to create WarperCreator");
776  return p;
777 }
778 
780  const string& type,
783  float scale)
784 {
785  Ptr<WarperCreator> p = createWarperCreator(type, first, last);
786  return p->create(scale);
787 }
788 
792 {
793  ptrdiff_t len = std::distance(first, last);
794  nargchk((len%2)==0);
795  int bl_width = 32;
796  int bl_height = 32;
797  for (; first != last; first += 2) {
798  string key(first->toString());
799  const MxArray& val = *(first + 1);
800  if (key == "Width")
801  bl_width = val.toInt();
802  else if (key == "Heigth")
803  bl_height = val.toInt();
804  else
805  mexErrMsgIdAndTxt("mexopencv:error",
806  "Unrecognized option %s", key.c_str());
807  }
808  return makePtr<BlocksGainCompensator>(bl_width, bl_height);
809 }
810 
812  const string& type,
815 {
816  //return ExposureCompensator::createDefault(ExposureCompensatorTypes[type]);
817  ptrdiff_t len = std::distance(first, last);
819  if (type == "NoExposureCompensator") {
820  nargchk(len==0);
821  p = makePtr<NoExposureCompensator>();
822  }
823  else if (type == "GainCompensator") {
824  nargchk(len==0);
825  p = makePtr<GainCompensator>();
826  }
827  else if (type == "BlocksGainCompensator")
828  p = createBlocksGainCompensator(first, last);
829  else
830  mexErrMsgIdAndTxt("mexopencv:error",
831  "Unrecognized exposure compensator %s", type.c_str());
832  if (p.empty())
833  mexErrMsgIdAndTxt("mexopencv:error",
834  "Failed to create ExposureCompensator");
835  return p;
836 }
837 
841 {
842  ptrdiff_t len = std::distance(first, last);
843  nargchk((len%2)==0);
845  for (; first != last; first += 2) {
846  string key(first->toString());
847  const MxArray& val = *(first + 1);
848  if (key == "CostFunction")
849  costFunc = DpCostFunctionMap[val.toString()];
850  else
851  mexErrMsgIdAndTxt("mexopencv:error",
852  "Unrecognized option %s", key.c_str());
853  }
854  return makePtr<DpSeamFinder>(costFunc);
855 }
856 
860 {
861  ptrdiff_t len = std::distance(first, last);
862  nargchk((len%2)==0);
864  float terminal_cost = 10000.0f;
865  float bad_region_penalty = 1000.0f;
866  for (; first != last; first += 2) {
867  string key(first->toString());
868  const MxArray& val = *(first + 1);
869  if (key == "CostType")
870  cost_type = GraphCutCostTypeMap[val.toString()];
871  else if (key == "TerminalCost")
872  terminal_cost = val.toFloat();
873  else if (key == "BadRegionPenaly")
874  bad_region_penalty = val.toFloat();
875  else
876  mexErrMsgIdAndTxt("mexopencv:error",
877  "Unrecognized option %s", key.c_str());
878  }
879  return makePtr<GraphCutSeamFinder>(cost_type, terminal_cost, bad_region_penalty);
880 }
881 
883  const string& type,
886 {
887  ptrdiff_t len = std::distance(first, last);
888  Ptr<SeamFinder> p;
889  if (type == "NoSeamFinder") {
890  nargchk(len==0);
891  p = makePtr<NoSeamFinder>();
892  }
893  else if (type == "VoronoiSeamFinder") {
894  nargchk(len==0);
895  p = makePtr<VoronoiSeamFinder>();
896  }
897  else if (type == "DpSeamFinder")
898  p = createDpSeamFinder(first, last);
899  else if (type == "GraphCutSeamFinder")
900  p = createGraphCutSeamFinder(first, last);
901 #if 0
902  //TODO: CUDA
903  else if (type == "GraphCutSeamFinderGpu")
904  p = createGraphCutSeamFinderGpu(first, last);
905 #endif
906  else
907  mexErrMsgIdAndTxt("mexopencv:error",
908  "Unrecognized seam finder %s", type.c_str());
909  if (p.empty())
910  mexErrMsgIdAndTxt("mexopencv:error", "Failed to create SeamFinder");
911  return p;
912 }
913 
917 {
918  ptrdiff_t len = std::distance(first, last);
919  nargchk((len%2)==0);
920  float sharpness = 0.02f;
921  for (; first != last; first += 2) {
922  string key(first->toString());
923  const MxArray& val = *(first + 1);
924  if (key == "Sharpness")
925  sharpness = val.toFloat();
926  else
927  mexErrMsgIdAndTxt("mexopencv:error",
928  "Unrecognized option %s", key.c_str());
929  }
930  return makePtr<FeatherBlender>(sharpness);
931 }
932 
936 {
937  ptrdiff_t len = std::distance(first, last);
938  nargchk((len%2)==0);
939  int try_gpu = false;
940  int num_bands = 5;
941  int weight_type = CV_32F;
942  for (; first != last; first += 2) {
943  string key(first->toString());
944  const MxArray& val = *(first + 1);
945  if (key == "TryGPU")
946  try_gpu = val.toBool();
947  else if (key == "NumBands")
948  num_bands = val.toInt();
949  else if (key == "WeightType")
950  weight_type = (val.isChar()) ?
951  ClassNameMap[val.toString()] : val.toInt();
952  else
953  mexErrMsgIdAndTxt("mexopencv:error",
954  "Unrecognized option %s", key.c_str());
955  }
956  return makePtr<MultiBandBlender>(try_gpu, num_bands, weight_type);
957 }
958 
960  const string& type,
963 {
964  //return Blender::createDefault(BlenderTypesMap[type]);
965  ptrdiff_t len = std::distance(first, last);
966  Ptr<Blender> p;
967  if (type == "NoBlender") {
968  nargchk(len==0);
969  p = makePtr<Blender>();
970  }
971  else if (type == "FeatherBlender")
972  p = createFeatherBlender(first, last);
973  else if (type == "MultiBandBlender")
974  p = createMultiBandBlender(first, last);
975  else
976  mexErrMsgIdAndTxt("mexopencv:error",
977  "Unrecognized blender %s", type.c_str());
978  if (p.empty())
979  mexErrMsgIdAndTxt("mexopencv:error", "Failed to create Blender");
980  return p;
981 }
CostFunction costFunction() const
const ConstMap< std::string, int > GraphCutCostTypeMap
Graph-Cut cost types.
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
MxArray toStruct(const ImageFeatures &feat)
Convert image features to scalar struct.
Ptr< cv::CompressedRectilinearWarper > createCompressedRectilinearWarper(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of CompressedRectilinearWarper using options in arguments.
int toInt() const
Convert MxArray to int.
Definition: MxArray.cpp:489
Ptr< OrbFeaturesFinder > createOrbFeaturesFinder(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of OrbFeaturesFinder using options in arguments.
const ConstMap< string, int > AKAZEDescriptorType
AKAZE descriptor type.
T distance(T... args)
mwSize numel() const
Number of elements in an array.
Definition: MxArray.hpp:546
Common definitions for the stitching module.
T at(mwIndex index) const
Template for numeric array element accessor.
Definition: MxArray.hpp:1250
vector< CameraParams > MxArrayToVectorCameraParams(const MxArray &arr)
Convert MxArray to std::vector<cv::details::CameraParams>
Ptr< FeaturesFinder > createFeaturesFinder(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FeaturesFinder using options in arguments.
ImageFeatures MxArrayToImageFeatures(const MxArray &arr, mwIndex idx)
Convert MxArray to cv::details::ImageFeatures.
Ptr< cv::PaniniWarper > createPaniniWarper(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of PaniniWarper using options in arguments.
#define CV_8U
Ptr< RotationWarper > createRotationWarper(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last, float scale)
Create an instance of RotationWarper using options in arguments.
DESCRIPTOR_MLDB_UPRIGHT
cv::Ptr< cv::detail::SurfFeaturesFinder > createSurfFeaturesFinder(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of SurfFeaturesFinder using options in arguments.
std::vector< uchar > inliers_mask
Ptr< FeaturesMatcher > createFeaturesMatcher(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FeaturesMatcher using options in arguments.
const ConstMap< string, int > KAZEDiffusivityType
KAZE Diffusivity type.
Ptr< cv::CompressedRectilinearPortraitWarper > createCompressedRectilinearPortraitWarper(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of CompressedRectilinearPortraitWarper using options in arguments.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
Ptr< BlocksGainCompensator > createBlocksGainCompensator(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BlocksGainCompensator using options in arguments.
STL class.
Ptr< BestOf2NearestRangeMatcher > createBestOf2NearestRangeMatcher(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BestOf2NearestRangeMatcher using options in arguments.
Mat getMat(int flags) const
vector< MatchesInfo > MxArrayToVectorMatchesInfo(const MxArray &arr)
Convert MxArray to std::vector<cv::details::MatchesInfo>
Ptr< AKAZEFeaturesFinder > createAKAZEFeaturesFinder(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of AKAZEFeaturesFinder using options in arguments.
#define CV_32F
Ptr< FeatherBlender > createFeatherBlender(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FeatherBlender using options in arguments.
uint32_t v
bool toBool() const
Convert MxArray to bool.
Definition: MxArray.cpp:510
Ptr< Y > dynamicCast() const
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...
Ptr< Blender > createBlender(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of Blender using options in arguments.
virtual Ptr< detail::RotationWarper > create(float scale) const=0
float toFloat() const
Convert MxArray to float.
Definition: MxArray.cpp:503
unsigned char uchar
std::vector< DMatch > matches
void setTermCriteria(const TermCriteria &term_criteria)
void setConfThresh(double conf_thresh)
bool isCell() const
Determine whether input is cell array.
Definition: MxArray.hpp:610
size_t mwIndex
unsigned pointer-width integer
Definition: tmwtypes.h:857
void setRefinementMask(const Mat &mask)
bool isField(const std::string &fieldName) const
Determine whether a struct array has a specified field.
Definition: MxArray.hpp:743
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
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Definition: MxArray.hpp:312
Ptr< GraphCutSeamFinder > createGraphCutSeamFinder(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of GraphCutSeamFinder using options in arguments.
bool isStruct() const
Determine whether input is structure array.
Definition: MxArray.hpp:708
Ptr< MultiBandBlender > createMultiBandBlender(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MultiBandBlender using options in arguments.
T size(T... args)
STL class.
bool empty() const
vector< ImageFeatures > MxArrayToVectorImageFeatures(const MxArray &arr)
Convert MxArray std::vector<cv::details::ImageFeatures>
Ptr< cv::PaniniPortraitWarper > createPaniniPortraitWarper(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of PaniniPortraitWarper using options in arguments.
ACCESS_READ
const ConstMap< std::string, cv::detail::DpSeamFinder::CostFunction > DpCostFunctionMap
Cost function types.
Ptr< DpSeamFinder > createDpSeamFinder(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of DpSeamFinder using options in arguments.
Ptr< WarperCreator > createWarperCreator(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of WarperCreator using options in arguments.
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Ptr< Estimator > createEstimator(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of Estimator using options in arguments.
double toDouble() const
Convert MxArray to double.
Definition: MxArray.cpp:496
Ptr< SeamFinder > createSeamFinder(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of SeamFinder using options in arguments.
const Mat refinementMask() const
CameraParams MxArrayToCameraParams(const MxArray &arr, mwIndex idx)
Convert MxArray to cv::details::CameraParams.
std::vector< KeyPoint > keypoints
int type() const
Ptr< BestOf2NearestMatcher > createBestOf2NearestMatcher(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BestOf2NearestMatcher using options in arguments.
DESCRIPTOR_KAZE_UPRIGHT
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
Ptr< ExposureCompensator > createExposureCompensator(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ExposureCompensator using options in arguments.
Ptr< AffineBestOf2NearestMatcher > createAffineBestOf2NearestMatcher(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of AffineBestOf2NearestMatcher using options in arguments.
Ptr< BundleAdjusterBase > createBundleAdjusterBase(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BundleAdjusterBase using options in arguments.
MatchesInfo MxArrayToMatchesInfo(const MxArray &arr, mwIndex idx)
Convert MxArray to cv::details::MatchesInfo.
Ptr< HomographyBasedEstimator > createHomographyBasedEstimator(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of HomographyBasedEstimator using options in arguments.