mexopencv  0.1
mex interface for opencv library
decomposeProjectionMatrix.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
20 MxArray toStruct(const Mat& rotMatrX, const Mat& rotMatrY,
21  const Mat& rotMatrZ, const Mat& eulerAngles)
22 {
23  const char* fieldnames[] = {
24  "rotMatrX", "rotMatrY", "rotMatrZ", "eulerAngles"};
25  MxArray s = MxArray::Struct(fieldnames, 4);
26  s.set("rotMatrX", rotMatrX);
27  s.set("rotMatrY", rotMatrY);
28  s.set("rotMatrZ", rotMatrZ);
29  s.set("eulerAngles", eulerAngles);
30  return s;
31 }
32 }
33 
41 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
42 {
43  // Check the number of arguments
44  nargchk(nrhs==1 && nlhs<=4);
45 
46  // Argument vector
47  vector<MxArray> rhs(prhs, prhs+nrhs);
48 
49  // Process
50  Mat projMatrix(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)),
51  cameraMatrix, rotMatrix, transVect,
52  rotMatrX, rotMatrY, rotMatrZ, eulerAngles;
53  decomposeProjectionMatrix(projMatrix, cameraMatrix, rotMatrix, transVect,
54  (nlhs>3 ? rotMatrX : noArray()),
55  (nlhs>3 ? rotMatrY : noArray()),
56  (nlhs>3 ? rotMatrZ : noArray()),
57  (nlhs>3 ? eulerAngles : noArray()));
58  plhs[0] = MxArray(cameraMatrix);
59  if (nlhs > 1)
60  plhs[1] = MxArray(rotMatrix);
61  if (nlhs > 2)
62  plhs[2] = MxArray(transVect);
63  if (nlhs > 3)
64  plhs[3] = toStruct(rotMatrX, rotMatrY, rotMatrZ, eulerAngles);
65 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
MxArray toStruct(const std::vector< cv::ml::DTrees::Node > &nodes)
Convert tree nodes to struct array.
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
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
Global constant definitions.