mexopencv  3.4.1
MEX interface for OpenCV library
decomposeProjectionMatrix.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 {
21 MxArray toStruct(const Mat& rotMatrX, const Mat& rotMatrY,
22  const Mat& rotMatrZ, const Mat& eulerAngles)
23 {
24  const char* fieldnames[] = {
25  "rotMatrX", "rotMatrY", "rotMatrZ", "eulerAngles"};
26  MxArray s = MxArray::Struct(fieldnames, 4);
27  s.set("rotMatrX", rotMatrX);
28  s.set("rotMatrY", rotMatrY);
29  s.set("rotMatrZ", rotMatrZ);
30  s.set("eulerAngles", eulerAngles);
31  return s;
32 }
33 }
34 
42 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
43 {
44  // Check the number of arguments
45  nargchk(nrhs==1 && nlhs<=4);
46 
47  // Argument vector
48  vector<MxArray> rhs(prhs, prhs+nrhs);
49 
50  // Process
51  Mat projMatrix(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)),
52  cameraMatrix, rotMatrix, transVect,
53  rotMatrX, rotMatrY, rotMatrZ, eulerAngles;
54  decomposeProjectionMatrix(projMatrix, cameraMatrix, rotMatrix, transVect,
55  (nlhs>3 ? rotMatrX : noArray()),
56  (nlhs>3 ? rotMatrY : noArray()),
57  (nlhs>3 ? rotMatrZ : noArray()),
58  (nlhs>3 ? eulerAngles : noArray()));
59  plhs[0] = MxArray(cameraMatrix);
60  if (nlhs > 1)
61  plhs[1] = MxArray(rotMatrix);
62  if (nlhs > 2)
63  plhs[2] = MxArray(transVect);
64  if (nlhs > 3)
65  plhs[3] = toStruct(rotMatrX, rotMatrY, rotMatrZ, eulerAngles);
66 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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
#define CV_32F
InputOutputArray noArray()
#define CV_64F
void decomposeProjectionMatrix(InputArray projMatrix, OutputArray cameraMatrix, OutputArray rotMatrix, OutputArray transVect, OutputArray rotMatrixX=noArray(), OutputArray rotMatrixY=noArray(), OutputArray rotMatrixZ=noArray(), OutputArray eulerAngles=noArray())
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 &rotMatrX, const Mat &rotMatrY, const Mat &rotMatrZ, const Mat &eulerAngles)
Create a new MxArray from decomposed projection matrix.
Global constant definitions.
cv::Mat toMat() const