mexopencv  3.4.1
MEX interface for OpenCV library
estimateGlobalMotionLeastSquares.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/videostab.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::videostab;
13 
14 namespace {
17  ("Translation", cv::videostab::MM_TRANSLATION)
18  ("TranslationAndScale", cv::videostab::MM_TRANSLATION_AND_SCALE)
19  ("Rotation", cv::videostab::MM_ROTATION)
20  ("Rigid", cv::videostab::MM_RIGID)
21  ("Similarity", cv::videostab::MM_SIMILARITY)
22  ("Affine", cv::videostab::MM_AFFINE)
23  ("Homography", cv::videostab::MM_HOMOGRAPHY)
24  ("Unknown", cv::videostab::MM_UNKNOWN);
25 }
26 
34 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
35 {
36  // Check the number of arguments
37  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
38 
39  // Argument vector
40  vector<MxArray> rhs(prhs, prhs+nrhs);
41 
42  // Option processing
43  int model = cv::videostab::MM_AFFINE;
44  for (int i=2; i<nrhs; i+=2) {
45  string key(rhs[i].toString());
46  if (key == "MotionModel")
47  model = MotionModelMap[rhs[i+1].toString()];
48  else
49  mexErrMsgIdAndTxt("mexopencv:error",
50  "Unrecognized option %s", key.c_str());
51  }
52 
53  // Process
54  Mat M;
55  float rmse = 0;
56  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
57  Mat points0(rhs[0].toMat(CV_32F)),
58  points1(rhs[1].toMat(CV_32F));
59  M = estimateGlobalMotionLeastSquares(points0, points1, model, &rmse);
60  }
61  else if (rhs[0].isCell() && rhs[1].isCell()) {
62  vector<Point2f> points0(rhs[0].toVector<Point2f>()),
63  points1(rhs[1].toVector<Point2f>());
64  M = estimateGlobalMotionLeastSquares(points0, points1, model, &rmse);
65  }
66  else
67  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
68  plhs[0] = MxArray(M);
69  if (nlhs > 1)
70  plhs[1] = MxArray(rmse);
71 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
Mat estimateGlobalMotionLeastSquares(InputOutputArray points0, InputOutputArray points1, int model=MM_AFFINE, float *rmse=0)
#define CV_32F
const ConstMap< std::string, cv::videostab::MotionModel > MotionModelMap
motion model types for option processing
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...
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
STL class.
Global constant definitions.
T c_str(T... args)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const