mexopencv  0.1
mex interface for opencv library
rectify3Collinear.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
26 MxArray toStruct(const Mat& R1, const Mat& R2, const Mat& R3,
27  const Mat& P1, const Mat& P2, const Mat& P3, const Mat& Q,
28  const Rect& roi1, const Rect& roi2, float ratio)
29 {
30  const char* fieldnames[] = {"R1", "R2", "R3", "P1", "P2", "P3", "Q",
31  "roi1", "roi2", "ratio"};
32  MxArray s = MxArray::Struct(fieldnames, 10);
33  s.set("R1", R1);
34  s.set("R2", R2);
35  s.set("R3", R3);
36  s.set("P1", P1);
37  s.set("P2", P2);
38  s.set("P3", P3);
39  s.set("Q", Q);
40  s.set("roi1", roi1);
41  s.set("roi2", roi2);
42  s.set("ratio", ratio);
43  return s;
44 }
45 }
46 
54 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
55 {
56  // Check the number of arguments
57  nargchk(nrhs>=11 && (nrhs%2)==1 && nlhs<=1);
58 
59  // Argument vector
60  vector<MxArray> rhs(prhs, prhs+nrhs);
61 
62  // Option processing
63  vector<Point2f> imgpt1, imgpt3;
64  double alpha = -1;
65  Size newImageSize;
66  int flags = cv::CALIB_ZERO_DISPARITY;
67  for (int i=11; i<nrhs; i+=2) {
68  string key(rhs[i].toString());
69  if (key == "ImgPoints1")
70  imgpt1 = rhs[i+1].toVector<Point2f>();
71  else if (key == "ImgPoints3")
72  imgpt3 = rhs[i+1].toVector<Point2f>();
73  else if (key == "Alpha")
74  alpha = rhs[i+1].toDouble();
75  else if (key == "NewImageSize")
76  newImageSize = rhs[i+1].toSize();
77  else if (key == "ZeroDisparity")
78  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_ZERO_DISPARITY);
79  else
80  mexErrMsgIdAndTxt("mexopencv:error",
81  "Unrecognized option %s",key.c_str());
82  }
83 
84  // Process
85  Mat cameraMatrix1(rhs[0].toMat(CV_64F)),
86  distCoeffs1(rhs[1].toMat(CV_64F)),
87  cameraMatrix2(rhs[2].toMat(CV_64F)),
88  distCoeffs2(rhs[3].toMat(CV_64F)),
89  cameraMatrix3(rhs[4].toMat(CV_64F)),
90  distCoeffs3(rhs[5].toMat(CV_64F)),
91  R12(rhs[7].toMat(CV_64F)),
92  T12(rhs[8].toMat(CV_64F)),
93  R13(rhs[9].toMat(CV_64F)),
94  T13(rhs[10].toMat(CV_64F)),
95  R1, R2, R3, P1, P2, P3, Q;
96  Size imageSize(rhs[6].toSize());
97  Rect roi1, roi2;
98  float ratio = rectify3Collinear(cameraMatrix1, distCoeffs1,
99  cameraMatrix2, distCoeffs2, cameraMatrix3, distCoeffs3,
100  imgpt1, imgpt3, imageSize, R12, T12, R13, T13,
101  R1, R2, R3, P1, P2, P3, Q, alpha, newImageSize, &roi1, &roi2, flags);
102  plhs[0] = toStruct(R1, R2, R3, P1, P2, P3, Q, roi1, roi2, ratio);
103 }
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
Definition: mexopencv.hpp:159
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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.
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.