34 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=4);
40 Mat distCoeffs, rvec, tvec;
41 bool useExtrinsicGuess =
false;
42 int iterationsCount = 100;
43 float reprojectionError = 8.0f;
44 double confidence = 0.99;
46 for (
int i=3; i<nrhs; i+=2) {
47 string key(rhs[i].toString());
48 if (key ==
"DistCoeffs")
49 distCoeffs = rhs[i+1].toMat(
CV_64F);
50 else if (key ==
"UseExtrinsicGuess")
51 useExtrinsicGuess = rhs[i+1].toBool();
52 else if (key ==
"Rvec")
53 rvec = rhs[i+1].toMat(
CV_64F);
54 else if (key ==
"Tvec")
55 tvec = rhs[i+1].toMat(
CV_64F);
56 else if (key ==
"Method")
58 else if (key ==
"IterationsCount")
59 iterationsCount = rhs[i+1].toInt();
60 else if (key ==
"ReprojectionError")
61 reprojectionError = rhs[i+1].toFloat();
62 else if (key ==
"Confidence")
63 confidence = rhs[i+1].toDouble();
66 "Unrecognized option %s", key.
c_str());
69 useExtrinsicGuess =
true;
75 if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
78 success =
solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs,
79 rvec, tvec, useExtrinsicGuess, iterationsCount, reprojectionError,
80 confidence, (nlhs>3 ? inliers :
noArray()), flags);
82 else if (rhs[0].isCell() && rhs[1].isCell()) {
85 success =
solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs,
86 rvec, tvec, useExtrinsicGuess, iterationsCount, reprojectionError,
87 confidence, (nlhs>3 ? inliers :
noArray()), flags);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
const ConstMap< string, int > PnPMethod
Method used for solving the pose estimation problem.
struct mxArray_tag mxArray
Forward declaration for mxArray.
InputOutputArray noArray()
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...
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
Global constant definitions.
bool solvePnPRansac(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int iterationsCount=100, float reprojectionError=8.0, double confidence=0.99, OutputArray inliers=noArray(), int flags=SOLVEPNP_ITERATIVE)
std::map wrapper with one-line initialization and lookup method.