mexopencv  3.4.1
MEX interface for OpenCV library
findTransformECC.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/video.hpp"
10 using namespace std;
11 using namespace cv;
12 
13 namespace {
16  ("Translation", cv::MOTION_TRANSLATION)
17  ("Euclidean", cv::MOTION_EUCLIDEAN)
18  ("Affine", cv::MOTION_AFFINE)
19  ("Homography", cv::MOTION_HOMOGRAPHY);
20 }
21 
29 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
30 {
31  // Check the number of arguments
32  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
33 
34  // Argument vector
35  vector<MxArray> rhs(prhs, prhs+nrhs);
36 
37  // Option processing
38  int motionType = cv::MOTION_AFFINE;
39  TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001);
40  Mat inputMask;
41  Mat warpMatrix;
42  for (int i=2; i<nrhs; i+=2) {
43  string key(rhs[i].toString());
44  if (key == "MotionType")
45  motionType = MotionTypeMap[rhs[i+1].toString()];
46  else if (key == "Criteria")
47  criteria = rhs[i+1].toTermCriteria();
48  else if (key == "Mask")
49  inputMask = rhs[i+1].toMat(CV_8U);
50  else if (key == "InputWarp")
51  warpMatrix = rhs[i+1].toMat(CV_32F);
52  else
53  mexErrMsgIdAndTxt("mexopencv:error",
54  "Unrecognized option %s", key.c_str());
55  }
56 
57  // Process
58  Mat templateImage(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)),
59  inputImage(rhs[1].toMat(rhs[1].isUint8() ? CV_8U : CV_32F));
60  double rho = findTransformECC(templateImage, inputImage, warpMatrix,
61  motionType, criteria, inputMask);
62  plhs[0] = MxArray(warpMatrix);
63  if (nlhs > 1)
64  plhs[1] = MxArray(rho);
65 }
MOTION_EUCLIDEAN
double findTransformECC(InputArray templateImage, InputArray inputImage, InputOutputArray warpMatrix, int motionType=MOTION_AFFINE, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), InputArray inputMask=noArray())
#define CV_8U
STL namespace.
const ConstMap< string, int > MotionTypeMap
motion types for option processing
MOTION_AFFINE
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_32F
MOTION_HOMOGRAPHY
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
MOTION_TRANSLATION
STL class.
Global constant definitions.
T c_str(T... args)
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
cv::Mat toMat() const