mexopencv  0.1
mex interface for opencv library
resize.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  // Determine variant
28  bool scale_variant = (nrhs>=3 &&
29  rhs[1].isNumeric() && rhs[1].numel()==1 &&
30  rhs[2].isNumeric() && rhs[2].numel()==1);
31  nargchk((nrhs%2) == (scale_variant ? 1 : 0));
32 
33  // Option processing
34  int interpolation = cv::INTER_LINEAR;
35  for (int i=(scale_variant ? 3 : 2); i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key=="Interpolation")
38  interpolation = InterpType[rhs[i+1].toString()];
39  else
40  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
41  }
42 
43  // Decide size/scale arguments
44  Size dsize;
45  double fx = 0, fy = 0;
46  if (scale_variant) {
47  fx = rhs[1].toDouble();
48  fy = rhs[2].toDouble();
49  }
50  else
51  dsize = rhs[1].toSize();
52 
53  // Process
54  Mat src(rhs[0].toMat()), dst;
55  resize(src, dst, dsize, fx, fy, interpolation);
56  plhs[0] = MxArray(dst);
57 }
const ConstMap< std::string, int > InterpType
Interpolation type map for option processing.
Definition: mexopencv.hpp:71
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: resize.cpp:19
Global constant definitions.