19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=5);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
28 Mat cameraMatrix, distCoeffs;
30 TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON);
31 for (
int i=3; i<nrhs; i+=2) {
32 string key(rhs[i].toString());
33 if (key ==
"CameraMatrix")
34 cameraMatrix = rhs[i+1].toMat(CV_64F);
35 else if (key ==
"DistCoeffs")
36 distCoeffs = rhs[i+1].toMat(CV_64F);
37 else if (key ==
"UseIntrinsicGuess")
38 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_USE_INTRINSIC_GUESS);
39 else if (key ==
"FixPrincipalPoint")
40 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_PRINCIPAL_POINT);
41 else if (key ==
"FixAspectRatio")
42 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_ASPECT_RATIO);
43 else if (key ==
"ZeroTangentDist")
44 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_ZERO_TANGENT_DIST);
45 else if (key ==
"FixK1")
46 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_K1);
47 else if (key ==
"FixK2")
48 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_K2);
49 else if (key ==
"FixK3")
50 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_K3);
51 else if (key ==
"FixK4")
52 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_K4);
53 else if (key ==
"FixK5")
54 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_K5);
55 else if (key ==
"FixK6")
56 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_K6);
57 else if (key ==
"RationalModel")
58 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_RATIONAL_MODEL);
59 else if (key ==
"ThinPrismModel")
60 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_THIN_PRISM_MODEL);
61 else if (key ==
"FixS1S2S3S4")
62 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_S1_S2_S3_S4);
63 else if (key ==
"TiltedModel")
64 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_TILTED_MODEL);
65 else if (key ==
"FixTauXTauY")
66 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_FIX_TAUX_TAUY);
67 else if (key ==
"UseLU")
68 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_USE_LU);
69 else if (key ==
"Criteria")
70 criteria = rhs[i+1].toTermCriteria();
72 mexErrMsgIdAndTxt(
"mexopencv:error",
73 "Unrecognized option %s",key.c_str());
77 vector<vector<Point3f> > objectPoints(MxArrayToVectorVectorPoint3<float>(rhs[0]));
78 vector<vector<Point2f> > imagePoints(MxArrayToVectorVectorPoint<float>(rhs[1]));
79 Size imageSize(rhs[2].toSize());
80 vector<Mat> rvecs, tvecs;
81 double reprojErr = calibrateCamera(objectPoints, imagePoints, imageSize,
82 cameraMatrix, distCoeffs, (nlhs>3 ? rvecs : noArray()),
83 (nlhs>4 ? tvecs : noArray()), flags, criteria);
84 plhs[0] =
MxArray(cameraMatrix);
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.