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)
26 const char* fieldnames[] = {
"R1",
"R2",
"P1",
"P2",
"Q",
"roi1",
"roi2"};
46 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
49 nargchk(nrhs>=7 && (nrhs%2)==1 && nlhs<=1);
52 vector<MxArray> rhs(prhs, prhs+nrhs);
55 int flags = cv::CALIB_ZERO_DISPARITY;
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();
67 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
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)),
78 Size imageSize(rhs[4].toSize());
80 stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2,
81 imageSize, R, T, R1, R2, P1, P2, Q, flags, alpha, newImageSize,
83 plhs[0] =
toStruct(R1, R2, P1, P2, Q, roi1, roi2);
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
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.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Global constant definitions.