mexopencv  3.4.1
MEX interface for OpenCV library
decomposeHomographyMat.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 {
20 MxArray toStruct(const vector<Mat>& rotations,
21  const vector<Mat>& translations, const vector<Mat>& normals)
22 {
23  const char* fieldnames[] = {"R", "t", "n"};
24  MxArray s = MxArray::Struct(fieldnames, 3);
25  s.set("R", rotations);
26  s.set("t", translations);
27  s.set("n", normals);
28  return s;
29 }
30 }
31 
39 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
40 {
41  // Check the number of arguments
42  nargchk(nrhs==2 && nlhs<=2);
43 
44  // Argument vector
45  vector<MxArray> rhs(prhs, prhs+nrhs);
46 
47  // Process
48  Mat H(rhs[0].toMat(CV_64F)),
49  K(rhs[1].toMat(CV_64F));
50  vector<Mat> rotations, translations, normals;
51  int nsols = decomposeHomographyMat(H, K, rotations, translations, normals);
52  plhs[0] = toStruct(rotations, translations, normals);
53  if (nlhs > 1)
54  plhs[1] = MxArray(nsols);
55 }
MxArray toStruct(const vector< Mat > &rotations, const vector< Mat > &translations, const vector< Mat > &normals)
Create a new MxArray from decomposed homography matrix.
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 CV_64F
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.
int decomposeHomographyMat(InputArray H, InputArray K, OutputArrayOfArrays rotations, OutputArrayOfArrays translations, OutputArrayOfArrays normals)
Global constant definitions.
cv::Mat toMat() const