mexopencv  3.4.1
MEX interface for OpenCV library
convertMaps.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>=1 && nlhs<=2);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Decide argument format
37  bool separate_variant = (nrhs>=2 && rhs[1].isNumeric());
38  nargchk((nrhs%2) == (separate_variant ? 0 : 1));
39 
40  // Option processing
41  int dstmap1type = -1;
42  bool nninterpolation = false;
43  for (int i=(separate_variant ? 2 : 1); i<nrhs; i+=2) {
44  string key(rhs[i].toString());
45  if (key == "DstMap1Type")
46  dstmap1type = (rhs[i+1].isChar()) ?
47  DstM1Type[rhs[i+1].toString()] : rhs[i+1].toInt();
48  else if (key == "NNInterpolation")
49  nninterpolation = rhs[i+1].toBool();
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54 
55  // Apply
56  Mat map1(rhs[0].toMat(rhs[0].isInt16() ? CV_16S : CV_32F)),
57  map2, dstmap1, dstmap2;
58  if (separate_variant)
59  map2 = rhs[1].toMat(rhs[1].isUint16() ? CV_16U : CV_32F);
60  convertMaps(map1, map2, dstmap1, dstmap2, dstmap1type, nninterpolation);
61  plhs[0] = MxArray(dstmap1);
62  if (nlhs>1)
63  plhs[1] = MxArray(dstmap2);
64 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_16SC2
#define CV_32FC2
#define CV_32F
void convertMaps(InputArray map1, InputArray map2, OutputArray dstmap1, OutputArray dstmap2, int dstmap1type, bool nninterpolation=false)
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
#define CV_16U
STL class.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: convertMaps.cpp:28
Global constant definitions.
#define CV_16S
const ConstMap< string, int > DstM1Type
Map type specification.
Definition: convertMaps.cpp:15
T c_str(T... args)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const