mexopencv  3.4.1
MEX interface for OpenCV library
initUndistortRectifyMap.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/imgproc.hpp"
10 using namespace std;
11 using namespace cv;
12 
13 namespace {
16  ("int16", CV_16SC2)
17  ("single1", CV_32FC1)
18  ("single2", CV_32FC2);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  Mat R, newCameraMatrix;
38  int m1type = -1; // (nlhs>1) ? CV_32FC1 : CV_32FC2
39  for (int i=3; i<nrhs; i+=2) {
40  string key(rhs[i].toString());
41  if (key == "R")
42  R = rhs[i+1].toMat(CV_64F);
43  else if (key == "NewCameraMatrix" || key == "P")
44  newCameraMatrix = rhs[i+1].toMat(CV_64F);
45  else if (key == "M1Type")
46  m1type = (rhs[i+1].isChar()) ?
47  M1Type[rhs[i+1].toString()] : rhs[i+1].toInt();
48  else
49  mexErrMsgIdAndTxt("mexopencv:error",
50  "Unrecognized option %s", key.c_str());
51  }
52 
53  // Process
54  Mat cameraMatrix(rhs[0].toMat(CV_64F)),
55  distCoeffs(rhs[1].toMat(CV_64F)),
56  map1, map2;
57  Size size(rhs[2].toSize());
58  initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix,
59  size, m1type, map1, map2);
60  plhs[0] = MxArray(map1);
61  if (nlhs>1)
62  plhs[1] = MxArray(map2);
63 }
const ConstMap< string, int > M1Type
Map type specification.
void initUndistortRectifyMap(InputArray cameraMatrix, InputArray distCoeffs, InputArray R, InputArray newCameraMatrix, Size size, int m1type, OutputArray map1, OutputArray map2)
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_16SC2
#define CV_32FC2
#define CV_64F
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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
size_t size() const