19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=3);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
28 int distType = cv::DIST_L2;
31 for (
int i=2; i<nrhs; i+=2) {
32 string key(rhs[i].toString());
33 if (key ==
"DistType")
34 distType = (rhs[i+1].isChar()) ?
35 DistType[rhs[i+1].toString()] : rhs[i+1].toInt();
36 else if (key ==
"Cost")
37 cost = rhs[i+1].toMat(CV_32F);
38 else if (key ==
"LowerBound")
39 lowerBound = rhs[i+1].toFloat();
41 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
43 if (distType==cv::DIST_USER && cost.empty())
44 mexErrMsgIdAndTxt(
"mexopencv:error",
45 "In case of user-defined distance, cost matrix must be defined");
48 Mat signature1(rhs[0].toMat(CV_32F)),
49 signature2(rhs[1].toMat(CV_32F)),
51 float emd = EMD(signature1, signature2, distType, cost,
52 (nlhs>1 && cost.empty() ? &lowerBound : NULL),
53 (nlhs>2 ? flow : noArray()));
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
const ConstMap< std::string, int > DistType
Distance types for Distance Transform and M-estimators.
Global constant definitions.