19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
29 double aspectRatio = 0;
30 for (
int i=4; i<nrhs; i+=2) {
31 string key(rhs[i].toString());
32 if (key==
"DistCoeffs")
33 distCoeffs = rhs[i+1].toMat(CV_64F);
34 else if (key==
"AspectRatio")
35 aspectRatio = rhs[i+1].toDouble();
37 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
41 Mat rvec(rhs[1].toMat(CV_64F)),
42 tvec(rhs[2].toMat(CV_64F)),
43 cameraMatrix(rhs[3].toMat(CV_64F)),
45 if (rhs[0].isNumeric()) {
46 Mat objectPoints(rhs[0].toMat(CV_64F)),
48 projectPoints(objectPoints, rvec, tvec, cameraMatrix, distCoeffs,
49 imagePoints, (nlhs>1 ? jacobian : noArray()), aspectRatio);
50 if (objectPoints.channels() == 1 && objectPoints.cols == 3)
51 imagePoints = imagePoints.reshape(1,0);
54 else if (rhs[0].isCell()) {
55 vector<Point3d> objectPoints(rhs[0].toVector<Point3d>());
56 vector<Point2d> imagePoints;
57 projectPoints(objectPoints, rvec, tvec, cameraMatrix, distCoeffs,
58 imagePoints, (nlhs>1 ? jacobian : noArray()), aspectRatio);
62 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid argument");
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.