How to use decomposeHomographyMat from openCV in Matlab
Show older comments
Hi, I am using mexopencv to use openCV's function decomposeHomographyMat in Matlab. I have calculated H(3x3) and K(3x3) matrix. Then I have written homography2RotTrans.cpp file consisting of all functions. But I am having a lot of troubles. homography2RotTrans is not accepting the inputs as well as i cannot convert the output of homography2RotTrans onto Matlab readable format. My .cpp code is below. Plz help
#include "opencvmex.hpp"
using namespace cv;
void checkInputs(int nrhs, const mxArray *prhs[]) { if (nrhs != 1) { mexErrMsgTxt("Incorrect number of inputs. Function expects 2 inputs."); }
if (!mxIsUint8(prhs[0]))
{
mexErrMsgTxt("Input image must be uint8.");
}
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
checkInputs(nrhs, prhs);
// inputs
cv::Ptr<cv::Mat> H = ocvMxArrayToMat_double(prhs[0], true);
cv::Ptr<cv::Mat> K = ocvMxArrayToMat_double(prhs[1], true);
std::vector<cv::Mat> Rs_decomp, ts_decomp, normals_decomp;
int solutions = decomposeHomographyMat(H, K, Rs_decomp, ts_decomp, normals_decomp);
// populate the outputs
plhs[0] = ocvMxArrayFromMat_double(Rs_decomp);
plhs[1] = ocvMxArrayFromMat_double(ts_decomp);
plhs[2] = ocvMxArrayFromMat_double(normals_decomp);
}
Answers (0)
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!