mexopencv  0.1
mex interface for opencv library
perspectiveTransform.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  // Process
28  Mat mtx(rhs[1].toMat(CV_64F));
29  if (rhs[0].isNumeric()) {
30  Mat src(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)), dst;
31  bool cn1 = (src.channels() == 1 && (src.cols == 2 || src.cols == 3));
32  if (cn1) src = src.reshape(src.cols, 0); // Nx2/Nx3 -> Nx1x2/Nx1x3
33  perspectiveTransform(src, dst, mtx);
34  if (cn1) dst = dst.reshape(1, 0); // Nx1x2/Nx1x3 -> Nx2/Nx3
35  plhs[0] = MxArray(dst);
36  }
37  else if (rhs[0].isCell() && !rhs[0].isEmpty()) {
38  mwSize n = rhs[0].at<MxArray>(0).numel();
39  if (n == 2) {
40  vector<Point2f> src(rhs[0].toVector<Point2f>()), dst;
41  perspectiveTransform(src, dst, mtx);
42  plhs[0] = MxArray(dst);
43  }
44  else if (n == 3) {
45  vector<Point3f> src(rhs[0].toVector<Point3f>()), dst;
46  perspectiveTransform(src, dst, mtx);
47  plhs[0] = MxArray(dst);
48  }
49  else
50  mexErrMsgIdAndTxt("mexopencv:error","Invalid input");
51  }
52  else
53  mexErrMsgIdAndTxt("mexopencv:error","Invalid input");
54 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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.