mexopencv  3.4.1
MEX interface for OpenCV library
warpAffine.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 && (nrhs%2)==0 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Mat dst;
30  Size dsize;
31  int flags = cv::INTER_LINEAR;
32  bool warp_inverse = false;
33  int borderMode = cv::BORDER_CONSTANT;
34  Scalar borderValue;
35  for (int i=2; i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key == "Dst")
38  dst = rhs[i+1].toMat();
39  else if (key == "DSize")
40  dsize = rhs[i+1].toSize();
41  else if (key == "Interpolation")
42  flags = InterpType[rhs[i+1].toString()];
43  else if (key == "WarpInverse")
44  warp_inverse = rhs[i+1].toBool();
45  else if (key == "BorderType")
46  borderMode = BorderType[rhs[i+1].toString()];
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  flags |= (warp_inverse ? cv::WARP_INVERSE_MAP : 0);
54  if (!dst.empty())
55  dsize = dst.size();
56 
57  // Process
58  Mat src(rhs[0].toMat()),
59  M(rhs[1].toMat(CV_64F));
60  warpAffine(src, dst, M, dsize, flags, 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 warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar &borderValue=Scalar())
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_64F
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
MatSize size
WARP_INVERSE_MAP
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.
Global constant definitions.
INTER_LINEAR
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: warpAffine.cpp:20
T c_str(T... args)
BORDER_CONSTANT
bool empty() const
cv::Mat toMat() const