mexopencv  0.1
mex interface for opencv library
convertMaps.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>=1 && nlhs<=2);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Decide argument format
36  bool separate_variant = (nrhs>=2 && rhs[1].isNumeric());
37  nargchk((nrhs%2) == (separate_variant ? 0 : 1));
38 
39  // Option processing
40  int dstmap1type = -1;
41  bool nninterpolation = false;
42  for (int i=(separate_variant ? 2 : 1); i<nrhs; i+=2) {
43  string key(rhs[i].toString());
44  if (key=="DstMap1Type")
45  dstmap1type = (rhs[i+1].isChar()) ?
46  DstM1Type[rhs[i+1].toString()] : rhs[i+1].toInt();
47  else if (key=="NNInterpolation")
48  nninterpolation = rhs[i+1].toBool();
49  else
50  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
51  }
52 
53  // Apply
54  Mat map1(rhs[0].toMat(rhs[0].isInt16() ? CV_16S : CV_32F)),
55  map2, dstmap1, dstmap2;
56  if (separate_variant)
57  map2 = rhs[1].toMat(rhs[1].isUint16() ? CV_16U : CV_32F);
58  convertMaps(map1, map2, dstmap1, dstmap2, dstmap1type, nninterpolation);
59  plhs[0] = MxArray(dstmap1);
60  if (nlhs>1)
61  plhs[1] = MxArray(dstmap2);
62 }
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.
Definition: convertMaps.cpp:27
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927