mexopencv  0.1
mex interface for opencv library
batchDistance.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int dtype = -1;
29  int normType = cv::NORM_L2;
30  int K = 0;
31  Mat mask;
32  int update = 0;
33  bool crosscheck = false;
34  for (int i=2; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key=="DType")
37  dtype = (rhs[i+1].isChar()) ?
38  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
39  else if (key=="NormType")
40  normType = NormType[rhs[i+1].toString()];
41  else if (key=="K")
42  K = rhs[i+1].toInt();
43  else if (key=="Mask")
44  mask = rhs[i+1].toMat(CV_8U);
45  else if (key=="Update")
46  update = rhs[i+1].toInt();
47  else if (key=="CrossCheck")
48  crosscheck = rhs[i+1].toBool();
49  else
50  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
51  }
52 
53  // Process
54  Mat src1(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)),
55  src2(rhs[1].toMat(rhs[1].isUint8() ? CV_8U : CV_32F));
56  Mat dst, nidx;
57  batchDistance(src1, src2, dst, dtype, (K>0 ? nidx : noArray()),
58  normType, K, mask, update, crosscheck);
59  plhs[0] = MxArray(dst);
60  if (nlhs>1)
61  plhs[1] = MxArray(nidx);
62 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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
Global constant definitions.
const ConstMap< std::string, int > NormType
Norm type map for option processing.
Definition: mexopencv.hpp:135