mexopencv  3.4.1
MEX interface for OpenCV library
mexopencv_videostab.cpp
Go to the documentation of this file.
1 
9 #include <typeinfo>
10 #include <cstdio>
11 #include <cstdarg>
12 using std::vector;
13 using std::string;
14 using std::const_mem_fun_ref_t;
15 using namespace cv;
16 using namespace cv::videostab;
17 
18 
19 // ==================== XXX ====================
20 
23  ("NS", cv::INPAINT_NS)
24  ("Telea", cv::INPAINT_TELEA);
25 
26 // HACK: mexPrintf doesn't correctly handle "%s" formatted messages when
27 // directly passing variadic to it. So we use vsnprintf first with a buffer,
28 // then pass the buffer to mexPrintf.
29 void LogToMATLAB::print(const char *format, ...)
30 {
31  // buffer
32  const int BUFSIZE = 255;
33  char buffer[BUFSIZE+1];
34 
35  // print formatted message to buffer
36  va_list args;
37  va_start(args, format);
38  vsnprintf(buffer, BUFSIZE, format, args);
39  va_end(args);
40 
41  // print buffered message in MATLAB
42  buffer[BUFSIZE] = '\0';
43  mexPrintf(buffer);
44 
45  //TODO: flush
46 }
47 
49 {
50  return RansacParams(
51  arr.at("Size").toInt(),
52  arr.at("Thresh").toFloat(),
53  arr.at("Eps").toFloat(),
54  arr.at("Prob").toFloat());
55 }
56 
58 {
60  s.set("Size", params.size);
61  s.set("Thresh", params.thresh);
62  s.set("Eps", params.eps);
63  s.set("Prob", params.prob);
64  return s;
65 }
66 
67 
68 // ==================== XXX ====================
69 
71 {
73  if (!p.empty())
74  s.set("TypeId", string(typeid(*p).name()));
75  return s;
76 }
77 
79 {
81  if (!p.empty()) {
82  s.set("TypeId", string(typeid(*p).name()));
84  if (!pp.empty()) {
85  s.set("Width", pp->width());
86  s.set("Height", pp->height());
87  s.set("FPS", pp->fps());
88  s.set("Count", pp->count());
89  }
90  }
91  return s;
92 }
93 
95 {
97  if (!p.empty()) {
98  s.set("TypeId", string(typeid(*p).name()));
99  s.set("Radius", p->radius());
100  // Frames, Motions, BlurrinessRates: data from stabilizer
102  if (!pp.empty()) {
103  s.set("Sensitivity", pp->sensitivity());
104  }
105  }
106  return s;
107 }
108 
110 {
112  if (!p.empty()) {
113  s.set("TypeId", string(typeid(*p).name()));
114  s.set("MotionModel", MotionModelInvMap[p->motionModel()]);
115  {
118  if (!pp.empty()) {
119  s.set("RansacParams", toStruct(pp->ransacParams()));
120  s.set("MinInlierRatio", pp->minInlierRatio());
121  }
122  }
123  }
124  return s;
125 }
126 
128 {
130  if (!p.empty()) {
131  s.set("TypeId", string(typeid(*p).name()));
132  //TODO: check each derived FeatureDetector, and return its props
133  }
134  return s;
135 }
136 
138 {
140  if (!p.empty()) {
141  s.set("TypeId", string(typeid(*p).name()));
144  if (!pp.empty()) {
145  s.set("WinSize", pp->winSize());
146  s.set("MaxLevel", pp->maxLevel());
147  }
148  }
149  return s;
150 }
151 
153 {
155  if (!p.empty()) {
156  s.set("TypeId", string(typeid(*p).name()));
157  //TODO: no CPU version, only CUDA
158  /*
159  Ptr<DensePyrLkOptFlowEstimatorGpu> pp =
160  p.dynamicCast<DensePyrLkOptFlowEstimatorGpu>();
161  if (!pp.empty()) {
162  s.set("WinSize", pp->winSize());
163  s.set("MaxLevel", pp->maxLevel());
164  }
165  */
166  }
167  return s;
168 }
169 
171 {
173  if (!p.empty()) {
174  s.set("TypeId", string(typeid(*p).name()));
177  if (!pp.empty()) {
178  s.set("CellSize", pp->cellSize());
179  s.set("RansacParams", toStruct(pp->ransacParams()));
180  }
181  }
182  return s;
183 }
184 
186 {
188  if (!p.empty()) {
189  s.set("TypeId", string(typeid(*p).name()));
190  s.set("MotionModel", MotionModelInvMap[p->motionModel()]);
193  if (!pp.empty()) {
194  s.set("Detector", toStruct(pp->detector())); // Ptr<FeatureDetector>
195  s.set("OpticalFlowEstimator", toStruct(pp->opticalFlowEstimator())); // Ptr<ISparseOptFlowEstimator>
196  s.set("OutlierRejector", toStruct(pp->outlierRejector())); // Ptr<IOutlierRejector>
197  }
198  }
199  return s;
200 }
201 
203 {
205  if (!p.empty()) {
206  s.set("TypeId", string(typeid(*p).name()));
207  s.set("MotionModel", MotionModelInvMap[p->motionModel()]);
208  s.set("Radius", p->radius());
209  // Frames, Motions, StabilizedFrames, StabilizationMotions: data from stabilizer
210  {
213  if (!pp.empty())
214  s.set("StdevThresh", pp->stdevThresh());
215  }
216  {
218  if (!pp.empty()) {
219  s.set("FlowErrorThreshold", pp->flowErrorThreshold());
220  s.set("DistThresh", pp->distThresh());
221  s.set("BorderMode", BorderTypeInv[pp->borderMode()]);
222  s.set("OptFlowEstimator", toStruct(pp->optFlowEstimator())); // Ptr<IDenseOptFlowEstimator>
223  }
224  }
225  {
227  if (!pp.empty())
228  s.set("Empty", pp->empty());
229  }
230  }
231  return s;
232 }
233 
235 {
237  if (!p.empty()) {
238  s.set("TypeId", string(typeid(*p).name()));
240  if (!pp.empty()) {
241  s.set("Radius", pp->radius());
242  s.set("Stdev", pp->stdev());
243  }
244  }
245  return s;
246 }
247 
249 {
251  if (!p.empty()) {
252  s.set("TypeId", string(typeid(*p).name()));
253  {
255  if (!pp.empty()) {
256  s.set("MotionModel", MotionModelInvMap[pp->motionModel()]);
257  s.set("FrameSize", pp->frameSize());
258  s.set("TrimRatio", pp->trimRatio());
259  s.set("Weight1", pp->weight1());
260  s.set("Weight2", pp->weight2());
261  s.set("Weight3", pp->weight3());
262  s.set("Weight4", pp->weight4());
263  }
264  }
265  {
267  if (!pp.empty()) {
268  s.set("Radius", pp->radius());
269  s.set("Stdev", pp->stdev());
270  }
271  }
272  {
275  if (!pp.empty())
276  s.set("Empty", pp->empty());
277  }
278  }
279  return s;
280 }
281 
283 {
285  if (!p.empty()) {
286  s.set("TypeId", string(typeid(*p).name()));
287  s.set("MotionEstimator", toStruct(p->motionEstimator())); // Ptr<ImageMotionEstimatorBase>
288  // FrameCount, Motions, Motions2, StabilizationMotions: data from stabilizer
291  if (!pp.empty())
292  s.set("Period", pp->period());
293  }
294  return s;
295 }
296 
297 
298 // ==================== XXX ====================
299 
300 Ptr<ILog> createILog(const string& type)
301 {
302  Ptr<ILog> p;
303  if (type == "LogToMATLAB")
304  p = makePtr<LogToMATLAB>();
305  else if (type == "LogToStdout")
306  p = makePtr<LogToStdout>();
307  else if (type == "NullLog")
308  p = makePtr<NullLog>();
309  else
310  mexErrMsgIdAndTxt("mexopencv:error",
311  "Unrecognized logger type %s", type.c_str());
312  if (p.empty())
313  mexErrMsgIdAndTxt("mexopencv:error",
314  "Failed to create ILog");
315  return p;
316 }
317 
321 {
322  ptrdiff_t len = std::distance(first, last);
323  nargchk(len>=1 && (len%2)==1);
324  string path(first->toString()); ++first;
325  bool volatileFrame = false;
326  for (; first != last; first += 2) {
327  string key(first->toString());
328  const MxArray& val = *(first + 1);
329  if (key == "VolatileFrame")
330  volatileFrame = val.toBool();
331  else
332  mexErrMsgIdAndTxt("mexopencv:error",
333  "Unrecognized option %s", key.c_str());
334  }
335  return makePtr<VideoFileSource>(path, volatileFrame);
336 }
337 
339  const string& type,
342 {
343  ptrdiff_t len = std::distance(first, last);
345  if (type == "VideoFileSource")
346  p = createVideoFileSource(first, last);
347  else if (type == "NullFrameSource") {
348  nargchk(len==0);
349  p = makePtr<NullFrameSource>();
350  }
351  else
352  mexErrMsgIdAndTxt("mexopencv:error",
353  "Unrecognized frame source %s", type.c_str());
354  if (p.empty())
355  mexErrMsgIdAndTxt("mexopencv:error",
356  "Failed to create IFrameSource");
357  return p;
358 }
359 
363 {
364  ptrdiff_t len = std::distance(first, last);
365  nargchk((len%2)==0);
366  Ptr<WeightingDeblurer> p = makePtr<WeightingDeblurer>();
367  if (p.empty())
368  mexErrMsgIdAndTxt("mexopencv:error",
369  "Failed to create WeightingDeblurer");
370  for (; first != last; first += 2) {
371  string key(first->toString());
372  const MxArray& val = *(first + 1);
373  // Frames, Motions, BlurrinessRates: data from stabilizer
374  if (key == "Radius")
375  p->setRadius(val.toInt());
376  else if (key == "Sensitivity")
377  p->setSensitivity(val.toFloat());
378  else
379  mexErrMsgIdAndTxt("mexopencv:error",
380  "Unrecognized option %s", key.c_str());
381  }
382  return p;
383 }
384 
386  const string& type,
389 {
390  ptrdiff_t len = std::distance(first, last);
392  if (type == "WeightingDeblurer")
393  p = createWeightingDeblurer(first, last);
394  else if (type == "NullDeblurer") {
395  nargchk(len==3);
396  p = makePtr<NullDeblurer>();
397  }
398  else
399  mexErrMsgIdAndTxt("mexopencv:error",
400  "Unrecognized deblurer %s", type.c_str());
401  if (p.empty())
402  mexErrMsgIdAndTxt("mexopencv:error",
403  "Failed to create DeblurerBase");
404  return p;
405 }
406 
410 {
411  ptrdiff_t len = std::distance(first, last);
412  nargchk((len%2)==0);
414  for (; first != last; first += 2) {
415  string key(first->toString());
416  const MxArray& val = *(first + 1);
417  if (key == "MotionModel")
418  model = MotionModelMap[val.toString()];
419  else
420  mexErrMsgIdAndTxt("mexopencv:error",
421  "Unrecognized option %s", key.c_str());
422  }
423  return makePtr<MotionEstimatorL1>(model);
424 }
425 
429 {
430  ptrdiff_t len = std::distance(first, last);
431  nargchk((len%2)==0);
433  RansacParams ransacParams = RansacParams::default2dMotion(model);
434  float minInlierRatio = 0.1f;
435  for (; first != last; first += 2) {
436  string key(first->toString());
437  const MxArray& val = *(first + 1);
438  if (key == "MotionModel")
439  model = MotionModelMap[val.toString()];
440  else if (key == "RansacParams")
441  ransacParams = (val.isStruct() ? toRansacParams(val) :
443  else if (key == "MinInlierRatio")
444  minInlierRatio = val.toFloat();
445  else
446  mexErrMsgIdAndTxt("mexopencv:error",
447  "Unrecognized option %s", key.c_str());
448  }
449  Ptr<MotionEstimatorRansacL2> p = makePtr<MotionEstimatorRansacL2>(model);
450  if (p.empty())
451  mexErrMsgIdAndTxt("mexopencv:error",
452  "Failed to create MotionEstimatorRansacL2");
453  p->setRansacParams(ransacParams);
454  p->setMinInlierRatio(minInlierRatio);
455  return p;
456 }
457 
459  const string& type,
462 {
464  if (type == "MotionEstimatorL1")
465  p = createMotionEstimatorL1(first, last);
466  else if (type == "MotionEstimatorRansacL2")
467  p = createMotionEstimatorRansacL2(first, last);
468  else
469  mexErrMsgIdAndTxt("mexopencv:error",
470  "Unrecognized motion estimator %s", type.c_str());
471  if (p.empty())
472  mexErrMsgIdAndTxt("mexopencv:error",
473  "Failed to create MotionEstimatorBase");
474  return p;
475 }
476 
480 {
481  ptrdiff_t len = std::distance(first, last);
482  nargchk((len%2)==0);
483  Ptr<SparsePyrLkOptFlowEstimator> p = makePtr<SparsePyrLkOptFlowEstimator>();
484  if (p.empty())
485  mexErrMsgIdAndTxt("mexopencv:error",
486  "Failed to create SparsePyrLkOptFlowEstimator");
487  for (; first != last; first += 2) {
488  string key(first->toString());
489  const MxArray& val = *(first + 1);
490  if (key == "WinSize")
491  p->setWinSize(val.toSize());
492  else if (key == "MaxLevel")
493  p->setMaxLevel(val.toInt());
494  else
495  mexErrMsgIdAndTxt("mexopencv:error",
496  "Unrecognized option %s", key.c_str());
497  }
498  return p;
499 }
500 
502  const string& type,
505 {
507  if (type == "SparsePyrLkOptFlowEstimator")
508  p = createSparsePyrLkOptFlowEstimator(first, last);
509  else
510  mexErrMsgIdAndTxt("mexopencv:error",
511  "Unrecognized sparse optical flow estimator %s", type.c_str());
512  if (p.empty())
513  mexErrMsgIdAndTxt("mexopencv:error",
514  "Failed to create ISparseOptFlowEstimator");
515  return p;
516 }
517 
519  const string& type,
522 {
524  if (type == "DensePyrLkOptFlowEstimatorGpu")
525  // TODO: no CPU version, only CUDA
526  ; //p = createDensePyrLkOptFlowEstimatorGpu(first, last);
527  else
528  mexErrMsgIdAndTxt("mexopencv:error",
529  "Unrecognized dense optical flow estimator %s", type.c_str());
530  if (p.empty())
531  mexErrMsgIdAndTxt("mexopencv:error",
532  "Failed to create IDenseOptFlowEstimator");
533  return p;
534 }
535 
539 {
540  ptrdiff_t len = std::distance(first, last);
541  nargchk((len%2)==0);
543  makePtr<TranslationBasedLocalOutlierRejector>();
544  if (p.empty())
545  mexErrMsgIdAndTxt("mexopencv:error",
546  "Failed to create TranslationBasedLocalOutlierRejector");
547  for (; first != last; first += 2) {
548  string key(first->toString());
549  const MxArray& val = *(first + 1);
550  if (key == "CellSize")
551  p->setCellSize(val.toSize());
552  else if (key == "RansacParams")
553  p->setRansacParams((val.isStruct()) ? toRansacParams(val) :
555  else
556  mexErrMsgIdAndTxt("mexopencv:error",
557  "Unrecognized option %s", key.c_str());
558  }
559  return p;
560 }
561 
563  const string& type,
566 {
567  ptrdiff_t len = std::distance(first, last);
569  if (type == "TranslationBasedLocalOutlierRejector")
571  else if (type == "NullOutlierRejector") {
572  nargchk(len==0);
573  p = makePtr<NullOutlierRejector>();
574  }
575  else
576  mexErrMsgIdAndTxt("mexopencv:error",
577  "Unrecognized outlier rejector %s", type.c_str());
578  if (p.empty())
579  mexErrMsgIdAndTxt("mexopencv:error",
580  "Failed to create IOutlierRejector");
581  return p;
582 }
583 
587 {
588  ptrdiff_t len = std::distance(first, last);
589  nargchk(len>=1 && (len%2)==1);
591  {
592  vector<MxArray> args(first->toVector<MxArray>()); ++first;
593  nargchk(args.size() >= 1);
595  args[0].toString(), args.begin() + 1, args.end());
596  p = makePtr<KeypointBasedMotionEstimator>(estimator);
597  }
598  if (p.empty())
599  mexErrMsgIdAndTxt("mexopencv:error",
600  "Failed to create KeypointBasedMotionEstimator");
601  for (; first != last; first += 2) {
602  string key(first->toString());
603  const MxArray& val = *(first + 1);
604  if (key == "MotionModel")
605  p->setMotionModel(MotionModelMap[val.toString()]);
606  else if (key == "Detector") {
607  vector<MxArray> args(val.toVector<MxArray>());
608  nargchk(args.size() >= 1);
610  args[0].toString(), args.begin() + 1, args.end());
611  p->setDetector(pp);
612  }
613  else if (key == "OpticalFlowEstimator") {
614  vector<MxArray> args(val.toVector<MxArray>());
615  nargchk(args.size() >= 1);
617  args[0].toString(), args.begin() + 1, args.end());
619  }
620  else if (key == "OutlierRejector") {
621  vector<MxArray> args(val.toVector<MxArray>());
622  nargchk(args.size() >= 1);
624  args[0].toString(), args.begin() + 1, args.end());
625  p->setOutlierRejector(pp);
626  }
627  else
628  mexErrMsgIdAndTxt("mexopencv:error",
629  "Unrecognized option %s", key.c_str());
630  }
631  return p;
632 }
633 
637 {
638  ptrdiff_t len = std::distance(first, last);
639  nargchk(len>=1 && (len%2)==1);
640  string path(first->toString()); ++first;
641  Ptr<FromFileMotionReader> p = makePtr<FromFileMotionReader>(path);
642  if (p.empty())
643  mexErrMsgIdAndTxt("mexopencv:error",
644  "Failed to create FromFileMotionReader");
645  for (; first != last; first += 2) {
646  string key(first->toString());
647  const MxArray& val = *(first + 1);
648  if (key == "MotionModel")
649  p->setMotionModel(MotionModelMap[val.toString()]);
650  else
651  mexErrMsgIdAndTxt("mexopencv:error",
652  "Unrecognized option %s", key.c_str());
653  }
654  return p;
655 }
656 
660 {
661  ptrdiff_t len = std::distance(first, last);
662  nargchk(len>=2 && (len%2)==0);
664  {
665  string path(first->toString()); ++first;
666  vector<MxArray> args(first->toVector<MxArray>()); ++first;
667  nargchk(args.size() >= 1);
669  args[0].toString(), args.begin() + 1, args.end());
670  p = makePtr<ToFileMotionWriter>(path, estimator);
671  }
672  if (p.empty())
673  mexErrMsgIdAndTxt("mexopencv:error",
674  "Failed to create ToFileMotionWriter");
675  for (; first != last; first += 2) {
676  string key(first->toString());
677  const MxArray& val = *(first + 1);
678  if (key == "MotionModel")
679  p->setMotionModel(MotionModelMap[val.toString()]);
680  else
681  mexErrMsgIdAndTxt("mexopencv:error",
682  "Unrecognized option %s", key.c_str());
683  }
684  return p;
685 }
686 
688  const string& type,
691 {
693  if (type == "KeypointBasedMotionEstimator")
694  p = createKeypointBasedMotionEstimator(first, last);
695  else if (type == "FromFileMotionReader")
696  p = createFromFileMotionReader(first, last);
697  else if (type == "ToFileMotionWriter")
698  p = createToFileMotionWriter(first, last);
699  else
700  mexErrMsgIdAndTxt("mexopencv:error",
701  "Unrecognized image motion estimator %s", type.c_str());
702  if (p.empty())
703  mexErrMsgIdAndTxt("mexopencv:error",
704  "Failed to create ImageMotionEstimatorBase");
705  return p;
706 }
707 
711 {
712  ptrdiff_t len = std::distance(first, last);
713  nargchk((len%2)==0);
714  int method = cv::INPAINT_TELEA;
715  double radius2 = 2.0;
716  int radius = 0;
718  for (; first != last; first += 2) {
719  string key(first->toString());
720  const MxArray& val = *(first + 1);
721  // Frames, Motions, StabilizedFrames, StabilizationMotions: data from stabilizer
722  if (key == "Method")
723  method = InpaintingAlgMap[val.toString()];
724  else if (key == "Radius2")
725  radius2 = val.toDouble();
726  else if (key == "MotionModel")
727  model = MotionModelMap[val.toString()];
728  else if (key == "Radius")
729  radius = val.toInt();
730  else
731  mexErrMsgIdAndTxt("mexopencv:error",
732  "Unrecognized option %s", key.c_str());
733  }
734  Ptr<ColorInpainter> p = makePtr<ColorInpainter>(method, radius2);
735  if (p.empty())
736  mexErrMsgIdAndTxt("mexopencv:error",
737  "Failed to create ColorInpainter");
738  p->setMotionModel(model);
739  p->setRadius(radius);
740  return p;
741 }
742 
746 {
747  ptrdiff_t len = std::distance(first, last);
748  nargchk((len%2)==0);
749  Ptr<ColorAverageInpainter> p = makePtr<ColorAverageInpainter>();
750  if (p.empty())
751  mexErrMsgIdAndTxt("mexopencv:error",
752  "Failed to create ColorAverageInpainter");
753  for (; first != last; first += 2) {
754  string key(first->toString());
755  const MxArray& val = *(first + 1);
756  // Frames, Motions, StabilizedFrames, StabilizationMotions: data from stabilizer
757  if (key == "MotionModel")
758  p->setMotionModel(MotionModelMap[val.toString()]);
759  else if (key == "Radius")
760  p->setRadius(val.toInt());
761  else
762  mexErrMsgIdAndTxt("mexopencv:error",
763  "Unrecognized option %s", key.c_str());
764  }
765  return p;
766 }
767 
771 {
772  ptrdiff_t len = std::distance(first, last);
773  nargchk((len%2)==0);
774  Ptr<ConsistentMosaicInpainter> p = makePtr<ConsistentMosaicInpainter>();
775  if (p.empty())
776  mexErrMsgIdAndTxt("mexopencv:error",
777  "Failed to create ConsistentMosaicInpainter");
778  for (; first != last; first += 2) {
779  string key(first->toString());
780  const MxArray& val = *(first + 1);
781  // Frames, Motions, StabilizedFrames, StabilizationMotions: data from stabilizer
782  if (key == "MotionModel")
783  p->setMotionModel(MotionModelMap[val.toString()]);
784  else if (key == "Radius")
785  p->setRadius(val.toInt());
786  else if (key == "StdevThresh")
787  p->setStdevThresh(val.toFloat());
788  else
789  mexErrMsgIdAndTxt("mexopencv:error",
790  "Unrecognized option %s", key.c_str());
791  }
792  return p;
793 }
794 
798 {
799  ptrdiff_t len = std::distance(first, last);
800  nargchk((len%2)==0);
801  Ptr<MotionInpainter> p = makePtr<MotionInpainter>();
802  if (p.empty())
803  mexErrMsgIdAndTxt("mexopencv:error",
804  "Failed to create MotionInpainter");
805  for (; first != last; first += 2) {
806  string key(first->toString());
807  const MxArray& val = *(first + 1);
808  // Frames, Motions, StabilizedFrames, StabilizationMotions: data from stabilizer
809  if (key == "MotionModel")
810  p->setMotionModel(MotionModelMap[val.toString()]);
811  else if (key == "Radius")
812  p->setRadius(val.toInt());
813  else if (key == "FlowErrorThreshold")
814  p->setFlowErrorThreshold(val.toFloat());
815  else if (key == "DistThreshold")
816  p->setDistThreshold(val.toFloat());
817  else if (key == "BorderMode")
818  p->setBorderMode(BorderType[val.toString()]);
819  else if (key == "OptFlowEstimator") {
820  vector<MxArray> args(val.toVector<MxArray>());
821  nargchk(args.size() >= 1);
823  args[0].toString(), args.begin() + 1, args.end());
824  p->setOptFlowEstimator(pp);
825  }
826  else
827  mexErrMsgIdAndTxt("mexopencv:error",
828  "Unrecognized option %s", key.c_str());
829  }
830  return p;
831 }
832 
836 {
837  ptrdiff_t len = std::distance(first, last);
838  nargchk(len>=1 && (len%2)==1);
839  Ptr<InpaintingPipeline> p = makePtr<InpaintingPipeline>();
840  if (p.empty())
841  mexErrMsgIdAndTxt("mexopencv:error",
842  "Failed to create InpaintingPipeline");
843  {
844  vector<vector<MxArray> > inpainters(first->toVector(
845  const_mem_fun_ref_t<vector<MxArray>, MxArray>(
846  &MxArray::toVector<MxArray>))); ++first;
847  for (vector<vector<MxArray> >::const_iterator it = inpainters.begin(); it != inpainters.end(); ++it) {
848  nargchk(it->size() >= 1);
850  (*it)[0].toString(), it->begin() + 1, it->end());
851  p->pushBack(inpainter);
852  }
853  }
854  for (; first != last; first += 2) {
855  string key(first->toString());
856  const MxArray& val = *(first + 1);
857  // Frames, Motions, StabilizedFrames, StabilizationMotions: data from stabilizer
858  if (key == "MotionModel")
859  p->setMotionModel(MotionModelMap[val.toString()]);
860  else if (key == "Radius")
861  p->setRadius(val.toInt());
862  else
863  mexErrMsgIdAndTxt("mexopencv:error",
864  "Unrecognized option %s", key.c_str());
865  }
866  return p;
867 }
868 
870  const string& type,
873 {
874  ptrdiff_t len = std::distance(first, last);
876  if (type == "ColorInpainter")
877  p = createColorInpainter(first, last);
878  else if (type == "ColorAverageInpainter")
879  p = createColorAverageInpainter(first, last);
880  else if (type == "ConsistentMosaicInpainter")
881  p = createConsistentMosaicInpainter(first, last);
882  else if (type == "MotionInpainter")
883  p = createMotionInpainter(first, last);
884  else if (type == "InpaintingPipeline")
885  p = createInpaintingPipeline(first, last);
886  else if (type == "NullInpainter") {
887  nargchk(len==0);
888  p = makePtr<NullInpainter>();
889  }
890  else
891  mexErrMsgIdAndTxt("mexopencv:error",
892  "Unrecognized inpainter %s", type.c_str());
893  if (p.empty())
894  mexErrMsgIdAndTxt("mexopencv:error",
895  "Failed to create InpainterBase");
896  return p;
897 }
898 
902 {
903  ptrdiff_t len = std::distance(first, last);
904  nargchk((len%2)==0);
905  int radius = 15;
906  float stdev = -1.0f;
907  for (; first != last; first += 2) {
908  string key(first->toString());
909  const MxArray& val = *(first + 1);
910  if (key == "Radius")
911  radius = val.toInt();
912  else if (key == "Stdev")
913  stdev = val.toFloat();
914  else
915  mexErrMsgIdAndTxt("mexopencv:error",
916  "Unrecognized option %s", key.c_str());
917  }
918  return makePtr<GaussianMotionFilter>(radius, stdev);
919 }
920 
922  const string& type,
925 {
927  if (type == "GaussianMotionFilter")
928  p = createGaussianMotionFilter(first, last);
929  else
930  mexErrMsgIdAndTxt("mexopencv:error",
931  "Unrecognized motion filter %s", type.c_str());
932  if (p.empty())
933  mexErrMsgIdAndTxt("mexopencv:error",
934  "Failed to create MotionFilterBase");
935  return p;
936 }
937 
941 {
942  ptrdiff_t len = std::distance(first, last);
943  nargchk((len%2)==0);
944  Ptr<LpMotionStabilizer> p = makePtr<LpMotionStabilizer>();
945  if (p.empty())
946  mexErrMsgIdAndTxt("mexopencv:error",
947  "Failed to create LpMotionStabilizer");
948  for (; first != last; first += 2) {
949  string key(first->toString());
950  const MxArray& val = *(first + 1);
951  if (key == "MotionModel")
952  p->setMotionModel(MotionModelMap[val.toString()]);
953  else if (key == "FrameSize")
954  p->setFrameSize(val.toSize());
955  else if (key == "TrimRatio")
956  p->setTrimRatio(val.toFloat());
957  else if (key == "Weight1")
958  p->setWeight1(val.toFloat());
959  else if (key == "Weight2")
960  p->setWeight2(val.toFloat());
961  else if (key == "Weight3")
962  p->setWeight3(val.toFloat());
963  else if (key == "Weight4")
964  p->setWeight4(val.toFloat());
965  else
966  mexErrMsgIdAndTxt("mexopencv:error",
967  "Unrecognized option %s", key.c_str());
968  }
969  return p;
970 }
971 
975 {
976  ptrdiff_t len = std::distance(first, last);
977  nargchk(len==1);
978  Ptr<MotionStabilizationPipeline> p = makePtr<MotionStabilizationPipeline>();
979  if (p.empty())
980  mexErrMsgIdAndTxt("mexopencv:error",
981  "Failed to create MotionStabilizationPipeline");
982  {
983  vector<vector<MxArray> > stabilizers(first->toVector(
984  const_mem_fun_ref_t<vector<MxArray>, MxArray>(
985  &MxArray::toVector<MxArray>))); ++first;
986  for (vector<vector<MxArray> >::const_iterator it = stabilizers.begin(); it != stabilizers.end(); ++it) {
987  nargchk(it->size() >= 1);
989  (*it)[0].toString(), it->begin() + 1, it->end());
990  p->pushBack(stabilizer);
991  }
992  }
993  return p;
994 }
995 
997  const string& type,
1000 {
1002  if (type == "LpMotionStabilizer")
1003  p = createLpMotionStabilizer(first, last);
1004  else if (type == "GaussianMotionFilter")
1005  p = createGaussianMotionFilter(first, last);
1006  else if (type == "MotionStabilizationPipeline")
1007  p = createMotionStabilizationPipeline(first, last);
1008  else
1009  mexErrMsgIdAndTxt("mexopencv:error",
1010  "Unrecognized motion stabilizer %s", type.c_str());
1011  if (p.empty())
1012  mexErrMsgIdAndTxt("mexopencv:error",
1013  "Failed to create IMotionStabilizer");
1014  return p;
1015 }
1016 
1020 {
1021  ptrdiff_t len = std::distance(first, last);
1022  nargchk((len%2)==0);
1024  makePtr<MoreAccurateMotionWobbleSuppressor>();
1025  if (p.empty())
1026  mexErrMsgIdAndTxt("mexopencv:error",
1027  "Failed to create MoreAccurateMotionWobbleSuppressor");
1028  for (; first != last; first += 2) {
1029  string key(first->toString());
1030  const MxArray& val = *(first + 1);
1031  // FrameCount, Motions, Motions2, StabilizationMotions: data from stabilizer
1032  if (key == "MotionEstimator") {
1033  vector<MxArray> args(val.toVector<MxArray>());
1034  nargchk(args.size() >= 1);
1036  args[0].toString(), args.begin() + 1, args.end());
1037  p->setMotionEstimator(pp);
1038  }
1039  else if (key == "Period")
1040  p->setPeriod(val.toInt());
1041  else
1042  mexErrMsgIdAndTxt("mexopencv:error",
1043  "Unrecognized option %s", key.c_str());
1044  }
1045  return p;
1046 }
1047 
1049  const string& type,
1052 {
1053  ptrdiff_t len = std::distance(first, last);
1055  if (type == "MoreAccurateMotionWobbleSuppressor")
1057  else if (type == "NullWobbleSuppressor") {
1058  nargchk(len==0);
1059  p = makePtr<NullWobbleSuppressor>();
1060  }
1061  else
1062  mexErrMsgIdAndTxt("mexopencv:error",
1063  "Unrecognized wobble suppressor %s", type.c_str());
1064  if (p.empty())
1065  mexErrMsgIdAndTxt("mexopencv:error",
1066  "Failed to create WobbleSuppressorBase");
1067  return p;
1068 }
Ptr< VideoFileSource > createVideoFileSource(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of VideoFileSource using options in arguments.
Ptr< FromFileMotionReader > createFromFileMotionReader(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FromFileMotionReader using options in arguments.
Common definitions for the videostab module.
int toInt() const
Convert MxArray to int.
Definition: MxArray.cpp:489
Ptr< ImageMotionEstimatorBase > createImageMotionEstimator(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ImageMotionEstimatorBase using options in arguments.
Ptr< MotionStabilizationPipeline > createMotionStabilizationPipeline(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MotionStabilizationPipeline using options in arguments.
T distance(T... args)
Ptr< WeightingDeblurer > createWeightingDeblurer(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of WeightingDeblurer using options in arguments.
T at(mwIndex index) const
Template for numeric array element accessor.
Definition: MxArray.hpp:1250
Ptr< ConsistentMosaicInpainter > createConsistentMosaicInpainter(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ConsistentMosaicInpainter using options in arguments.
void setMotionEstimator(Ptr< ImageMotionEstimatorBase > val)
Ptr< ColorInpainter > createColorInpainter(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ColorInpainter using options in arguments.
virtual void setRadius(int val)
MxArray toStruct(const RansacParams &params)
Convert RansacParams to MxArray.
Ptr< WobbleSuppressorBase > createWobbleSuppressorBase(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of WobbleSuppressorBase using options in arguments.
Ptr< MotionEstimatorL1 > createMotionEstimatorL1(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MotionEstimatorL1 using options in arguments.
Ptr< SparsePyrLkOptFlowEstimator > createSparsePyrLkOptFlowEstimator(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of SparsePyrLkOptFlowEstimator using options in arguments.
Ptr< GaussianMotionFilter > createGaussianMotionFilter(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of GaussianMotionFilter using options in arguments.
virtual MotionModel motionModel() const
void pushBack(Ptr< IMotionStabilizer > stabilizer)
T end(T... args)
Ptr< IMotionStabilizer > createIMotionStabilizer(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of IMotionStabilizer using options in arguments.
Ptr< MoreAccurateMotionWobbleSuppressor > createMoreAccurateMotionWobbleSuppressor(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MoreAccurateMotionWobbleSuppressor using options in arguments.
Ptr< ImageMotionEstimatorBase > motionEstimator() const
Ptr< ColorAverageInpainter > createColorAverageInpainter(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ColorAverageInpainter using options in arguments.
Ptr< MotionEstimatorBase > createMotionEstimatorBase(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MotionEstimatorBase using options in arguments.
void setOpticalFlowEstimator(Ptr< ISparseOptFlowEstimator > val)
RansacParams(int size, float thresh, float eps, float prob)
MotionModel
Ptr< ISparseOptFlowEstimator > opticalFlowEstimator() const
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
virtual int radius() const
virtual int radius() const
void setOptFlowEstimator(Ptr< IDenseOptFlowEstimator > val)
Ptr< MotionInpainter > createMotionInpainter(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MotionInpainter using options in arguments.
Ptr< InpainterBase > createInpainterBase(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of InpainterBase using options in arguments.
Ptr< IDenseOptFlowEstimator > createIDenseOptFlowEstimator(const string &type, vector< MxArray >::const_iterator, vector< MxArray >::const_iterator)
Create an instance of IDenseOptFlowEstimator using options in arguments.
virtual void setMotionModel(MotionModel val)
void setDetector(Ptr< FeatureDetector > val)
virtual void setRadius(int val)
STL class.
LIBMWMEX_API_EXTERN_C int mexPrintf(const char *fmt,...)
mex equivalent to MATLAB&#39;s "disp" function
const ConstMap< int, std::string > BorderTypeInv
Inverse border type map for option processing.
Definition: mexopencv.hpp:76
Ptr< LpMotionStabilizer > createLpMotionStabilizer(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of LpMotionStabilizer using options in arguments.
const ConstMap< cv::videostab::MotionModel, std::string > MotionModelInvMap
inverse motion model types for option processing
Ptr< IOutlierRejector > outlierRejector() const
Ptr< DeblurerBase > createDeblurerBase(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of DeblurerBase using options in arguments.
virtual void setMotionModel(MotionModel val)
bool toBool() const
Convert MxArray to bool.
Definition: MxArray.cpp:510
Ptr< Y > dynamicCast() const
const ConstMap< std::string, cv::videostab::MotionModel > MotionModelMap
motion model types for option processing
cv::Ptr< cv::FeatureDetector > createFeatureDetector(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Factory function for FeatureDetector creation.
void setRansacParams(const RansacParams &val)
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...
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:66
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
Ptr< FeatureDetector > detector() const
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< ISparseOptFlowEstimator > createISparseOptFlowEstimator(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ISparseOptFlowEstimator using options in arguments.
Ptr< IFrameSource > createIFrameSource(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of IFrameSource using options in arguments.
void setFlowErrorThreshold(float val)
T size(T... args)
INPAINT_TELEA
Ptr< ILog > createILog(const string &type)
Create an instance of ILog of the specified type.
MotionModel motionModel() const
STL class.
bool empty() const
void setOutlierRejector(Ptr< IOutlierRejector > val)
const ConstMap< string, int > InpaintingAlgMap
inpainting algorithm types for option processing
T begin(T... args)
Ptr< IDenseOptFlowEstimator > optFlowEstimator() const
Ptr< IOutlierRejector > createIOutlierRejector(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of IOutlierRejector using options in arguments.
Ptr< TranslationBasedLocalOutlierRejector > createTranslationBasedLocalOutlierRejector(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of createTranslationBasedLocalOutlierRejector using options in arguments...
Ptr< MotionEstimatorRansacL2 > createMotionEstimatorRansacL2(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MotionEstimatorRansacL2 using options in arguments.
virtual void print(const char *format,...)
void pushBack(Ptr< InpainterBase > inpainter)
Ptr< ToFileMotionWriter > createToFileMotionWriter(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of ToFileMotionWriter using options in arguments.
virtual MotionModel motionModel() const
virtual void setMotionModel(MotionModel val)
int type() const
RansacParams toRansacParams(const MxArray &arr)
Convert MxArray to RansacParams.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
virtual void setMotionModel(MotionModel val)
virtual void setRadius(int val)
Format format() const
void setMotionModel(MotionModel val)
INPAINT_NS
virtual MotionModel motionModel() const
void setDistThreshold(float val)
Ptr< InpaintingPipeline > createInpaintingPipeline(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of InpaintingPipeline using options in arguments.
Ptr< MotionFilterBase > createMotionFilterBase(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of MotionFilterBase using options in arguments.
Ptr< KeypointBasedMotionEstimator > createKeypointBasedMotionEstimator(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of KeypointBasedMotionEstimator using options in arguments.
static RansacParams default2dMotion(MotionModel model)
virtual void setMotionModel(MotionModel val)