mexopencv  3.4.1
MEX interface for OpenCV library
resize.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  // Determine variant
29  bool scale_variant = (nrhs>=3 &&
30  rhs[1].isNumeric() && rhs[1].numel()==1 &&
31  rhs[2].isNumeric() && rhs[2].numel()==1);
32  nargchk((nrhs%2) == (scale_variant ? 1 : 0));
33 
34  // Option processing
35  int interpolation = cv::INTER_LINEAR;
36  for (int i=(scale_variant ? 3 : 2); i<nrhs; i+=2) {
37  string key(rhs[i].toString());
38  if (key == "Interpolation")
39  interpolation = InterpType[rhs[i+1].toString()];
40  else
41  mexErrMsgIdAndTxt("mexopencv:error",
42  "Unrecognized option %s", key.c_str());
43  }
44 
45  // Decide size/scale arguments
46  Size dsize;
47  double fx = 0, fy = 0;
48  if (scale_variant) {
49  fx = rhs[1].toDouble();
50  fy = rhs[2].toDouble();
51  }
52  else
53  dsize = rhs[1].toSize();
54 
55  // Process
56  Mat src(rhs[0].toMat()), dst;
57  resize(src, dst, dsize, fx, fy, interpolation);
58  plhs[0] = MxArray(dst);
59 }
const ConstMap< std::string, int > InterpType
Interpolation type map for option processing.
Definition: mexopencv.hpp:85
STL namespace.
void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: resize.cpp:20
Global constant definitions.
INTER_LINEAR
T c_str(T... args)
cv::Mat toMat() const