mexopencv  0.1
mex interface for opencv library
stereoRectify.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
23 MxArray toStruct(const Mat& R1, const Mat& R2, const Mat& P1, const Mat& P2,
24  const Mat& Q, const Rect& roi1, const Rect& roi2)
25 {
26  const char* fieldnames[] = {"R1", "R2", "P1", "P2", "Q", "roi1", "roi2"};
27  MxArray s = MxArray::Struct(fieldnames, 7);
28  s.set("R1", R1);
29  s.set("R2", R2);
30  s.set("P1", P1);
31  s.set("P2", P2);
32  s.set("Q", Q);
33  s.set("roi1", roi1);
34  s.set("roi2", roi2);
35  return s;
36 }
37 }
38 
46 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
47 {
48  // Check the number of arguments
49  nargchk(nrhs>=7 && (nrhs%2)==1 && nlhs<=1);
50 
51  // Argument vector
52  vector<MxArray> rhs(prhs, prhs+nrhs);
53 
54  // Option processing
55  int flags = cv::CALIB_ZERO_DISPARITY;
56  double alpha = -1;
57  Size newImageSize;
58  for (int i=7; i<nrhs; i+=2) {
59  string key(rhs[i].toString());
60  if (key == "ZeroDisparity")
61  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_ZERO_DISPARITY);
62  else if (key == "Alpha")
63  alpha = rhs[i+1].toDouble();
64  else if (key == "NewImageSize")
65  newImageSize = rhs[i+1].toSize();
66  else
67  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
68  }
69 
70  // Process
71  Mat cameraMatrix1(rhs[0].toMat(CV_64F)),
72  distCoeffs1(rhs[1].toMat(CV_64F)),
73  cameraMatrix2(rhs[2].toMat(CV_64F)),
74  distCoeffs2(rhs[3].toMat(CV_64F)),
75  R(rhs[5].toMat(CV_64F)),
76  T(rhs[6].toMat(CV_64F)),
77  R1, R2, P1, P2, Q;
78  Size imageSize(rhs[4].toSize());
79  Rect roi1, roi2;
80  stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2,
81  imageSize, R, T, R1, R2, P1, P2, Q, flags, alpha, newImageSize,
82  &roi1, &roi2);
83  plhs[0] = toStruct(R1, R2, P1, P2, Q, roi1, roi2);
84 }
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
Definition: mexopencv.hpp:159
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
MxArray toStruct(const std::vector< cv::ml::DTrees::Node > &nodes)
Convert tree nodes to struct array.
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
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Definition: MxArray.hpp:312
Global constant definitions.