mexopencv  0.1
mex interface for opencv library
matchTemplate.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  ("SqDiff", cv::TM_SQDIFF)
16  ("SqDiffNormed", cv::TM_SQDIFF_NORMED)
17  ("CCorr", cv::TM_CCORR)
18  ("CCorrNormed", cv::TM_CCORR_NORMED)
19  ("CCoeff", cv::TM_CCOEFF)
20  ("CCoeffNormed", cv::TM_CCOEFF_NORMED);
21 }
22 
30 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
31 {
32  // Check the number of arguments
33  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
34 
35  // Argument vector
36  vector<MxArray> rhs(prhs, prhs+nrhs);
37 
38  // Option processing
39  int method = cv::TM_SQDIFF;
40  Mat mask;
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  MatchMethod[rhs[i+1].toString()] : rhs[i+1].toInt());
46  else if (key=="Mask")
47  mask = rhs[i+1].toMat(CV_8U);
48  else
49  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
50  }
51 
52  // Process
53  Mat image(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)),
54  templ(rhs[1].toMat(rhs[1].isUint8() ? CV_8U : CV_32F)),
55  result;
56  matchTemplate(image, templ, result, method, mask);
57  plhs[0] = MxArray(result);
58 }
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927