mexopencv  3.4.1
MEX interface for OpenCV library
fisheyeStereoRectify.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 
13 namespace {
22 MxArray toStruct(const Mat& R1, const Mat& R2, const Mat& P1, const Mat& P2,
23  const Mat& Q)
24 {
25  const char* fieldnames[] = {"R1", "R2", "P1", "P2", "Q"};
26  MxArray s = MxArray::Struct(fieldnames, 5);
27  s.set("R1", R1);
28  s.set("R2", R2);
29  s.set("P1", P1);
30  s.set("P2", P2);
31  s.set("Q", Q);
32  return s;
33 }
34 }
35 
43 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
44 {
45  // Check the number of arguments
46  nargchk(nrhs>=7 && (nrhs%2)==1 && nlhs<=1);
47 
48  // Argument vector
49  vector<MxArray> rhs(prhs, prhs+nrhs);
50 
51  // Option processing
52  int flags = cv::CALIB_ZERO_DISPARITY;
53  Size newImageSize;
54  double balance = 0.0;
55  double fov_scale = 1.0;
56  for (int i=7; i<nrhs; i+=2) {
57  string key(rhs[i].toString());
58  if (key == "ZeroDisparity")
59  UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::CALIB_ZERO_DISPARITY);
60  else if (key == "NewImageSize")
61  newImageSize = rhs[i+1].toSize();
62  else if (key == "Balance")
63  balance = rhs[i+1].toDouble();
64  else if (key == "FOVScale")
65  fov_scale = rhs[i+1].toDouble();
66  else
67  mexErrMsgIdAndTxt("mexopencv:error",
68  "Unrecognized option %s", key.c_str());
69  }
70 
71  // Process
72  Mat K1(rhs[0].toMat(CV_64F)),
73  D1(rhs[1].toMat(CV_64F)),
74  K2(rhs[2].toMat(CV_64F)),
75  D2(rhs[3].toMat(CV_64F)),
76  R(rhs[5].toMat(CV_64F)),
77  T(rhs[6].toMat(CV_64F)),
78  R1, R2, P1, P2, Q;
79  Size imageSize(rhs[4].toSize());
80  fisheye::stereoRectify(K1, D1, K2, D2, imageSize, R, T, R1, R2, P1, P2, Q,
81  flags, newImageSize, balance, fov_scale);
82  plhs[0] = toStruct(R1, R2, P1, P2, Q);
83 }
void stereoRectify(InputArray cameraMatrix1, InputArray distCoeffs1, InputArray cameraMatrix2, InputArray distCoeffs2, Size imageSize, InputArray R, InputArray T, OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags=CALIB_ZERO_DISPARITY, double alpha=-1, Size newImageSize=Size(), Rect *validPixROI1=0, Rect *validPixROI2=0)
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
#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...
CALIB_ZERO_DISPARITY
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
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Definition: MxArray.hpp:312
STL class.
MxArray toStruct(const Mat &R1, const Mat &R2, const Mat &P1, const Mat &P2, const Mat &Q)
Create a new MxArray from stereo rectified transforms.
Global constant definitions.
T c_str(T... args)
cv::Mat toMat() const