mexopencv  0.1
mex interface for opencv library
findTransformECC.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
14 const ConstMap<string,int> MotionTypeMap = ConstMap<string,int>
15  ("Translation", cv::MOTION_TRANSLATION)
16  ("Euclidean", cv::MOTION_EUCLIDEAN)
17  ("Affine", cv::MOTION_AFFINE)
18  ("Homography", cv::MOTION_HOMOGRAPHY);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  int motionType = cv::MOTION_AFFINE;
38  TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001);
39  Mat inputMask;
40  Mat warpMatrix;
41  for (int i=2; i<nrhs; i+=2) {
42  string key(rhs[i].toString());
43  if (key == "MotionType")
44  motionType = MotionTypeMap[rhs[i+1].toString()];
45  else if (key == "Criteria")
46  criteria = rhs[i+1].toTermCriteria();
47  else if (key == "Mask")
48  inputMask = rhs[i+1].toMat(CV_8U);
49  else if (key == "InputWarp")
50  warpMatrix = rhs[i+1].toMat(CV_32F);
51  else
52  mexErrMsgIdAndTxt("mexopencv:error",
53  "Unrecognized option %s", key.c_str());
54  }
55 
56  // Process
57  Mat templateImage(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)),
58  inputImage(rhs[1].toMat(rhs[1].isUint8() ? CV_8U : CV_32F));
59  double rho = findTransformECC(templateImage, inputImage, warpMatrix,
60  motionType, criteria, inputMask);
61  plhs[0] = MxArray(warpMatrix);
62  if (nlhs > 1)
63  plhs[1] = MxArray(rho);
64 }
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927