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