mexopencv  0.1
mex interface for opencv library
drawMatches.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>=5 && (nrhs%2)==1 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Mat outImg;
29  Scalar matchColor(Scalar::all(-1));
30  Scalar singlePointColor(Scalar::all(-1));
31  vector<char> matchesMask;
32  int flags = DrawMatchesFlags::DEFAULT;
33  for (int i=5; i<nrhs; i+=2) {
34  string key(rhs[i].toString());
35  if (key=="MatchColor")
36  matchColor = rhs[i+1].toScalar();
37  else if (key=="SinglePointColor")
38  singlePointColor = rhs[i+1].toScalar();
39  else if (key=="MatchesMask")
40  rhs[i+1].toMat(CV_8S).reshape(1,1).copyTo(matchesMask);
41  else if (key=="NotDrawSinglePoints")
42  UPDATE_FLAG(flags, rhs[i+1].toBool(),
43  DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
44  else if (key=="DrawRichKeypoints")
45  UPDATE_FLAG(flags, rhs[i+1].toBool(),
46  DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
47  else if (key=="OutImage") {
48  outImg = rhs[i+1].toMat(CV_8U);
49  flags |= DrawMatchesFlags::DRAW_OVER_OUTIMG;
50  }
51  else
52  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
53  }
54 
55  // Process
56  Mat img1(rhs[0].toMat(CV_8U)),
57  img2(rhs[2].toMat(CV_8U));
58  vector<KeyPoint> keypoints1(rhs[1].toVector<KeyPoint>()),
59  keypoints2(rhs[3].toVector<KeyPoint>());
60  vector<DMatch> matches1to2(rhs[4].toVector<DMatch>());
61  drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg,
62  matchColor, singlePointColor, matchesMask, flags);
63  plhs[0] = MxArray(outImg);
64 }
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
Definition: mexopencv.hpp:159
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: drawMatches.cpp:19
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.