27 const Mat& cameraMatrix2,
const Mat& distCoeffs2,
const Mat& R,
28 const Mat&
T,
const Mat& E,
const Mat& F,
double reprojErr)
30 const char* fieldnames[] = {
"cameraMatrix1",
"distCoeffs1",
31 "cameraMatrix2",
"distCoeffs2",
"R",
"T",
"E",
"F",
"reprojErr"};
33 s.
set(
"cameraMatrix1", cameraMatrix1);
34 s.
set(
"distCoeffs1", distCoeffs1);
35 s.
set(
"cameraMatrix2", cameraMatrix2);
36 s.
set(
"distCoeffs2", distCoeffs2);
41 s.
set(
"reprojErr", reprojErr);
56 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
62 Mat cameraMatrix1, distCoeffs1,
63 cameraMatrix2, distCoeffs2,
66 TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6);
67 for (
int i=4; i<nrhs; i+=2) {
68 string key(rhs[i].toString());
69 if (key ==
"CameraMatrix1")
70 cameraMatrix1 = rhs[i+1].toMat(
CV_64F);
71 else if (key ==
"DistCoeffs1")
72 distCoeffs1 = rhs[i+1].toMat(
CV_64F);
73 else if (key ==
"CameraMatrix2")
74 cameraMatrix2 = rhs[i+1].toMat(
CV_64F);
75 else if (key ==
"DistCoeffs2")
76 distCoeffs2 = rhs[i+1].toMat(
CV_64F);
78 R = rhs[i+1].toMat(
CV_64F);
81 else if (key ==
"FixIntrinsic")
83 else if (key ==
"UseIntrinsicGuess")
85 else if (key ==
"UseExtrinsicGuess")
87 else if (key ==
"FixPrincipalPoint")
89 else if (key ==
"FixFocalLength")
91 else if (key ==
"FixAspectRatio")
93 else if (key ==
"SameFocalLength")
95 else if (key ==
"ZeroTangentDist")
97 else if (key ==
"FixTangentDist")
99 else if (key ==
"FixK1")
101 else if (key ==
"FixK2")
103 else if (key ==
"FixK3")
105 else if (key ==
"FixK4")
107 else if (key ==
"FixK5")
109 else if (key ==
"FixK6")
111 else if (key ==
"RationalModel")
113 else if (key ==
"ThinPrismModel")
115 else if (key ==
"FixS1S2S3S4")
117 else if (key ==
"TiltedModel")
119 else if (key ==
"FixTauXTauY")
121 else if (key ==
"UseLU")
123 else if (key ==
"UseQR")
125 else if (key ==
"Criteria")
126 criteria = rhs[i+1].toTermCriteria();
129 "Unrecognized option %s", key.
c_str());
136 Size imageSize(rhs[3].toSize());
137 Mat E, F, perViewErrors;
138 double reprojErr =
stereoCalibrate(objectPoints, imagePoints1, imagePoints2,
139 cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize,
140 R,
T, E, F, (nlhs>1 ? perViewErrors :
noArray()), flags, criteria);
141 plhs[0] =
toStruct(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2,
142 R,
T, E, F, reprojErr);
144 plhs[1] =
MxArray(perViewErrors);
CALIB_FIX_PRINCIPAL_POINT
CALIB_USE_INTRINSIC_GUESS
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, Size imageSize, InputOutputArray R, InputOutputArray T, OutputArray E, OutputArray F, OutputArray perViewErrors, int flags=CALIB_FIX_INTRINSIC, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6))
InputOutputArray noArray()
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
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...
CALIB_USE_EXTRINSIC_GUESS
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output 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.
MxArray toStruct(const Mat &cameraMatrix1, const Mat &distCoeffs1, const Mat &cameraMatrix2, const Mat &distCoeffs2, const Mat &R, const Mat &T, const Mat &E, const Mat &F, double reprojErr)
Create a new MxArray from stereo calibration results.