mexopencv  3.4.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",
51  "Unrecognized option %s", key.c_str());
52  }
53 
54  // Process
55  Mat src1(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)),
56  src2(rhs[1].toMat(rhs[1].isUint8() ? CV_8U : CV_32F));
57  Mat dst, nidx;
58  batchDistance(src1, src2, dst, dtype, (K>0 ? nidx : noArray()),
59  normType, K, mask, update, crosscheck);
60  plhs[0] = MxArray(dst);
61  if (nlhs>1)
62  plhs[1] = MxArray(nidx);
63 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void batchDistance(InputArray src1, InputArray src2, OutputArray dist, int dtype, OutputArray nidx, int normType=NORM_L2, int K=0, InputArray mask=noArray(), int update=0, bool crosscheck=false)
#define CV_32F
InputOutputArray noArray()
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
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
STL class.
Global constant definitions.
T c_str(T... args)
const ConstMap< std::string, int > NormType
Norm type map for option processing.
Definition: mexopencv.hpp:150
cv::Mat toMat() const