mexopencv  0.1
mex interface for opencv library
warpAffine.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 && (nrhs%2)==0 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Mat dst;
29  Size dsize;
30  int flags = cv::INTER_LINEAR;
31  bool warp_inverse = false;
32  int borderMode = cv::BORDER_CONSTANT;
33  Scalar borderValue;
34  for (int i=2; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key=="Dst")
37  dst = rhs[i+1].toMat();
38  else if (key=="DSize")
39  dsize = rhs[i+1].toSize();
40  else if (key=="Interpolation")
41  flags = InterpType[rhs[i+1].toString()];
42  else if (key=="WarpInverse")
43  warp_inverse = rhs[i+1].toBool();
44  else if (key=="BorderType")
45  borderMode = BorderType[rhs[i+1].toString()];
46  else if (key=="BorderValue")
47  borderValue = rhs[i+1].toScalar();
48  else
49  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
50  }
51  flags |= (warp_inverse ? cv::WARP_INVERSE_MAP : 0);
52  if (!dst.empty())
53  dsize = dst.size();
54 
55  // Process
56  Mat src(rhs[0].toMat()),
57  M(rhs[1].toMat(CV_64F));
58  warpAffine(src, dst, M, dsize, flags, borderMode, borderValue);
59  plhs[0] = MxArray(dst);
60 }
const ConstMap< std::string, int > InterpType
Interpolation type map for option processing.
Definition: mexopencv.hpp:71
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: warpAffine.cpp:19