mexopencv  3.4.1
MEX interface for OpenCV library
drawKeypoints.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>=2 && (nrhs%2)==0 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Mat outImg;
30  Scalar color(Scalar::all(-1));
31  int flags = DrawMatchesFlags::DEFAULT;
32  for (int i=2; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "Color")
35  color = (rhs[i+1].isChar()) ?
36  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
37  else if (key == "DrawRichKeypoints")
38  UPDATE_FLAG(flags, rhs[i+1].toBool(),
39  DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
40  else if (key == "OutImage") {
41  outImg = rhs[i+1].toMat(CV_8U);
42  flags |= DrawMatchesFlags::DRAW_OVER_OUTIMG;
43  }
44  else
45  mexErrMsgIdAndTxt("mexopencv:error",
46  "Unrecognized option %s", key.c_str());
47  }
48 
49  // Process
50  Mat image(rhs[0].toMat(CV_8U));
51  vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
52  drawKeypoints(image, keypoints, outImg, color, flags);
53  plhs[0] = MxArray(outImg);
54 }
void drawKeypoints(InputArray image, const std::vector< KeyPoint > &keypoints, InputOutputArray outImage, const Scalar &color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT)
#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.
#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