mexopencv  0.1
mex interface for opencv library
compareHist.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
15  ("Correlation", cv::HISTCMP_CORREL)
16  ("ChiSquare", cv::HISTCMP_CHISQR)
17  ("Intersection", cv::HISTCMP_INTERSECT)
18  ("Bhattacharyya", cv::HISTCMP_BHATTACHARYYA)
19  ("Hellinger", cv::HISTCMP_HELLINGER)
20  ("AltChiSquare", cv::HISTCMP_CHISQR_ALT)
21  ("KullbackLeibler", cv::HISTCMP_KL_DIV);
22 }
23 
31 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
32 {
33  // Check the number of arguments
34  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
35 
36  // Argument vector
37  vector<MxArray> rhs(prhs, prhs+nrhs);
38 
39  // Option processing
40  int method = cv::HISTCMP_CORREL;
41  for (int i=2; i<nrhs; i+=2) {
42  string key(rhs[i].toString());
43  if (key=="Method")
44  method = (rhs[i+1].isChar()) ?
45  HistComp[rhs[i+1].toString()] : rhs[i+1].toInt();
46  else
47  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
48  }
49 
50  // Process
51  double d = 0;
52  if (rhs[0].isSparse() && rhs[1].isSparse()) {
53  SparseMat H1(rhs[0].toSparseMat(CV_32F)),
54  H2(rhs[1].toSparseMat(CV_32F));
55  d = compareHist(H1, H2, method);
56  }
57  else {
58  MatND H1(rhs[0].toMatND(CV_32F)),
59  H2(rhs[1].toMatND(CV_32F));
60  d = compareHist(H1, H2, method);
61  }
62  plhs[0] = MxArray(d);
63 }
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.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: compareHist.cpp:31