Closed Nickstaut closed 6 years ago
i can still make it using the mexopencv.hpp to make my own
Correct. If a module is missing in mexopencv, it just means we haven't gotten around to write wrappers for it, but you can always create your own MEX-files if you need a specific opencv function not currently exposed.
As for your mistake, the gateway function in a MEX-file must be named mexFunction
, as described in MATLAB docs, i.e:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
}
Other than that, your code should work.
I looked at opencv docs, here's my version of the wrapper for this function:
#include "mexopencv.hpp"
#include "opencv2/rgbd.hpp"
using namespace std;
using namespace cv;
using namespace cv::rgbd;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// Check the number of arguments
nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=1);
// Argument vector
vector<MxArray> rhs(prhs, prhs+nrhs);
// Option processing
Mat registeredDistCoeffs;
bool depthDilation = false;
for (int i=5; i<nrhs; i+=2) {
string key(rhs[i].toString());
if (key == "DistCoeffs")
registeredDistCoeffs = rhs[i+1].toMat(CV_32F);
else if (key == "DepthDilation")
depthDilation = rhs[i+1].toBool()
else
mexErrMsgIdAndTxt("mexopencv:error",
"Unrecognized option %s", key.c_str());
}
// Process
Matx33f unregisteredCameraMatrix(rhs[0].toMatx<float,3,3>()),
registeredCameraMatrix(rhs[1].toMatx<float,3,3>());
Matx44f Rt(rhs[2].toMatx<float,4,4>());
Mat unregisteredDepth(rhs[3].toMat(rhs[3].isUint16() ? CV_16U :
(rhs[3].isSingle() ? CV_32F : CV_64F)));
Size outputImagePlaneSize(rhs[4].toSize());
Mat registeredDepth;
registerDepth(unregisteredCameraMatrix, registeredCameraMatrix,
registeredDistCoeffs, Rt, unregisteredDepth, outputImagePlaneSize,
registeredDepth, depthDilation);
plhs[0] = MxArray(registeredDepth);
}
I'll consider the rgbd module next for adding to mexopencv.
Thank you very much for your quick response. I no longer get the error and can call the function just fine.
Hello,
I recently started using mexopencv and it is great. I know several opencv_contrib modules are not supported like the rgbd module. What is not completely clear to me is if this means there are no premade functions but i can still make it using the mexopencv.hpp to make my own or if it is completely impossible.
I attempted to mexcompile a simple function from the rgbd module:
The compilation did not give any errors but when i try to call this function i get the following error
I have no experience with c++ at all so i'm wondering if i did something wrong or if it is not possible at this time to make mexfunctions using mexopencv for the rgbd module.
Thanks in advance