mexopencv  0.1
mex interface for opencv library
initUndistortRectifyMap.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
15  ("int16", CV_16SC2)
16  ("single1", CV_32FC1)
17  ("single2", CV_32FC2);
18 }
19 
27 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
28 {
29  // Check the number of arguments
30  nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  Mat R;
37  int m1type = -1; // (nlhs>1) ? CV_32FC1 : CV_32FC2
38  for (int i=4; i<nrhs; i+=2) {
39  string key(rhs[i].toString());
40  if (key=="R")
41  R = rhs[i+1].toMat(CV_64F);
42  else if (key=="M1Type")
43  m1type = (rhs[i+1].isChar()) ?
44  M1Type[rhs[i+1].toString()] : rhs[i+1].toInt();
45  else
46  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
47  }
48 
49  // Process
50  Mat cameraMatrix(rhs[0].toMat(CV_64F)),
51  distCoeffs(rhs[1].toMat(CV_64F)),
52  newCameraMatrix(rhs[2].toMat(CV_64F)),
53  map1, map2;
54  Size size(rhs[3].toSize());
55  initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix,
56  size, m1type, map1, map2);
57  plhs[0] = MxArray(map1);
58  if (nlhs>1)
59  plhs[1] = MxArray(map2);
60 }
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927