mexopencv  3.4.1
MEX interface for OpenCV library
initWideAngleProjMap.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 
22  ("Ortho", cv::PROJ_SPHERICAL_ORTHO)
23  ("EqRect", cv::PROJ_SPHERICAL_EQRECT);
24 }
25 
33 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
34 {
35  // Check the number of arguments
36  nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=3);
37 
38  // Argument vector
39  vector<MxArray> rhs(prhs, prhs+nrhs);
40 
41  // Option processing
42  int m1type = -1;
43  int projType = cv::PROJ_SPHERICAL_EQRECT;
44  double alpha = 0;
45  for (int i=4; i<nrhs; i+=2) {
46  string key(rhs[i].toString());
47  if (key == "M1Type")
48  m1type = (rhs[i+1].isChar()) ?
49  M1Type[rhs[i+1].toString()] : rhs[i+1].toInt();
50  else if (key == "ProjType")
51  projType = ProjTypeMap[rhs[i+1].toString()];
52  else if (key == "Alpha")
53  alpha = rhs[i+1].toDouble();
54  else
55  mexErrMsgIdAndTxt("mexopencv:error",
56  "Unrecognized option %s", key.c_str());
57  }
58 
59  // Process
60  Mat cameraMatrix(rhs[0].toMat(CV_64F)),
61  distCoeffs(rhs[1].toMat(CV_64F)),
62  map1, map2;
63  Size imageSize(rhs[2].toSize());
64  int destImageWidth = rhs[3].toInt();
65  float scale = initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
66  destImageWidth, m1type, map1, map2, projType, alpha);
67  plhs[0] = MxArray(map1);
68  if (nlhs > 1)
69  plhs[1] = MxArray(map2);
70  if (nlhs > 2)
71  plhs[2] = MxArray(scale);
72 }
const ConstMap< string, int > M1Type
Map type specification.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
STL namespace.
float initWideAngleProjMap(InputArray cameraMatrix, InputArray distCoeffs, Size imageSize, int destImageWidth, int m1type, OutputArray map1, OutputArray map2, int projType=PROJ_SPHERICAL_EQRECT, double alpha=0)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_16SC2
#define CV_32FC2
PROJ_SPHERICAL_EQRECT
#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
STL class.
Global constant definitions.
T c_str(T... args)
PROJ_SPHERICAL_ORTHO
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const
const ConstMap< string, int > ProjTypeMap
projection types for option processing