mexopencv  3.4.1
MEX interface for OpenCV library
fisheyeCalibrate.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/calib3d.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=5);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Mat K, D;
30  int flags = 0;
31  TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 100, DBL_EPSILON);
32  for (int i=3; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "CameraMatrix")
35  K = rhs[i+1].toMat(CV_64F);
36  else if (key == "DistCoeffs")
37  D = rhs[i+1].toMat(CV_64F);
38  else if (key == "UseIntrinsicGuess")
39  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_USE_INTRINSIC_GUESS);
40  else if (key == "RecomputeExtrinsic")
41  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC);
42  else if (key == "CheckCond")
43  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_CHECK_COND);
44  else if (key == "FixSkew")
45  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_FIX_SKEW);
46  else if (key == "FixK1")
47  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_FIX_K1);
48  else if (key == "FixK2")
49  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_FIX_K2);
50  else if (key == "FixK3")
51  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_FIX_K3);
52  else if (key == "FixK4")
53  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_FIX_K4);
54  else if (key == "FixPrincipalPoint")
55  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::fisheye::CALIB_FIX_PRINCIPAL_POINT);
56  else if (key == "Criteria")
57  criteria = rhs[i+1].toTermCriteria();
58  else
59  mexErrMsgIdAndTxt("mexopencv:error",
60  "Unrecognized option %s", key.c_str());
61  }
62 
63  // Process
64  vector<vector<Point3d> > objectPoints(MxArrayToVectorVectorPoint3<double>(rhs[0]));
65  vector<vector<Point2d> > imagePoints(MxArrayToVectorVectorPoint<double>(rhs[1]));
66  Size imageSize(rhs[2].toSize());
67  vector<Mat> rvecs, tvecs;
68  double rms = fisheye::calibrate(
69  objectPoints, imagePoints, imageSize, K, D,
70  (nlhs>3 ? rvecs : noArray()),
71  (nlhs>4 ? tvecs : noArray()),
72  flags, criteria);
73  plhs[0] = MxArray(K);
74  if (nlhs > 1)
75  plhs[1] = MxArray(D);
76  if (nlhs > 2)
77  plhs[2] = MxArray(rms);
78  if (nlhs > 3)
79  plhs[3] = MxArray(rvecs);
80  if (nlhs > 4)
81  plhs[4] = MxArray(tvecs);
82 }
STL namespace.
double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size &image_size, InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags=0, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 100, DBL_EPSILON))
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
InputOutputArray noArray()
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
Definition: mexopencv.hpp:174
#define CV_64F
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.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
Global constant definitions.
T c_str(T... args)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.