mexopencv  0.1
mex interface for opencv library
remap.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=2 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Decide argument format
28  bool separate_variant = (nrhs>=3 && rhs[2].isNumeric());
29  nargchk((nrhs%2) == (separate_variant ? 1 : 0));
30 
31  // Option processing
32  Mat dst;
33  int interpolation = cv::INTER_LINEAR;
34  int borderMode = cv::BORDER_CONSTANT;
35  Scalar borderValue;
36  for (int i=(separate_variant ? 3 : 2); i<nrhs; i+=2) {
37  string key(rhs[i].toString());
38  if (key=="Dst")
39  dst = rhs[i+1].toMat();
40  else if (key=="Interpolation")
41  interpolation = (rhs[i+1].isChar()) ?
42  InterpType[rhs[i+1].toString()] : rhs[i+1].toInt();
43  else if (key=="BorderType")
44  borderMode = (rhs[i+1].isChar()) ?
45  BorderType[rhs[i+1].toString()] : rhs[i+1].toInt();
46  else if (key=="BorderValue")
47  borderValue = rhs[i+1].toScalar();
48  else
49  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
50  }
51 
52  // Process
53  Mat src(rhs[0].toMat()),
54  map1(rhs[1].toMat(rhs[1].isInt16() ? CV_16S : CV_32F)),
55  map2;
56  if (separate_variant)
57  map2 = rhs[2].toMat(rhs[2].isUint16() ? CV_16U : CV_32F);
58  remap(src, dst, map1, map2, interpolation, borderMode, borderValue);
59  plhs[0] = MxArray(dst);
60 }
const ConstMap< std::string, int > InterpType
Interpolation type map for option processing.
Definition: mexopencv.hpp:71
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: remap.cpp:19
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:52
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
Global constant definitions.