mexopencv  3.4.1
MEX interface for OpenCV library
drawMatches.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/features2d.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Mat outImg;
30  Scalar matchColor(Scalar::all(-1));
31  Scalar singlePointColor(Scalar::all(-1));
32  vector<char> matchesMask;
33  int flags = DrawMatchesFlags::DEFAULT;
34  for (int i=5; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key == "MatchColor")
37  matchColor = (rhs[i+1].isChar()) ?
38  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
39  else if (key == "SinglePointColor")
40  singlePointColor = (rhs[i+1].isChar()) ?
41  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
42  else if (key == "MatchesMask")
43  rhs[i+1].toMat(CV_8S).reshape(1,1).copyTo(matchesMask);
44  else if (key == "NotDrawSinglePoints")
45  UPDATE_FLAG(flags, rhs[i+1].toBool(),
46  DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
47  else if (key == "DrawRichKeypoints")
48  UPDATE_FLAG(flags, rhs[i+1].toBool(),
49  DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
50  else if (key == "OutImage") {
51  outImg = rhs[i+1].toMat(CV_8U);
52  flags |= DrawMatchesFlags::DRAW_OVER_OUTIMG;
53  }
54  else
55  mexErrMsgIdAndTxt("mexopencv:error",
56  "Unrecognized option %s", key.c_str());
57  }
58 
59  // Process
60  Mat img1(rhs[0].toMat(CV_8U)),
61  img2(rhs[2].toMat(CV_8U));
62  vector<KeyPoint> keypoints1(rhs[1].toVector<KeyPoint>()),
63  keypoints2(rhs[3].toVector<KeyPoint>());
64  vector<DMatch> matches1to2(rhs[4].toVector<DMatch>());
65  drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg,
66  matchColor, singlePointColor, matchesMask, flags);
67  plhs[0] = MxArray(outImg);
68 }
void drawMatches(InputArray img1, const std::vector< KeyPoint > &keypoints1, InputArray img2, const std::vector< KeyPoint > &keypoints2, const std::vector< DMatch > &matches1to2, InputOutputArray outImg, const Scalar &matchColor=Scalar::all(-1), const Scalar &singlePointColor=Scalar::all(-1), const std::vector< char > &matchesMask=std::vector< char >(), int flags=DrawMatchesFlags::DEFAULT)
#define CV_8U
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: drawMatches.cpp:20
STL namespace.
#define CV_8S
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
Definition: mexopencv.hpp:174
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, cv::Scalar > ColorType
Translates MATLAB color names (see ColorSpec) into OpenCV scalars.
Definition: mexopencv.hpp:55
static Scalar_< double > all(double v0)
cv::Mat toMat() const