mexopencv  3.4.1
MEX interface for OpenCV library
evaluateFeatureDetector.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "mexopencv_features2d.hpp" // createFeatureDetector
10 #include "opencv2/features2d.hpp"
11 using namespace std;
12 using namespace cv;
13 
21 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
22 {
23  // Check the number of arguments
24  nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=2);
25 
26  // Argument vector
27  vector<MxArray> rhs(prhs, prhs+nrhs);
28 
29  // Option processing
30  Ptr<FeatureDetector> fdetector;
31  for (int i=5; i<nrhs; i+=2) {
32  string key(rhs[i].toString());
33  if (key == "Detector") {
34  if (rhs[i+1].isChar())
35  fdetector = createFeatureDetector(
36  rhs[i+1].toString(), rhs.end(), rhs.end());
37  else if (rhs[i+1].isCell() && rhs[i+1].numel() >= 1) {
38  vector<MxArray> args(rhs[i+1].toVector<MxArray>());
39  fdetector = createFeatureDetector(
40  args[0].toString(), args.begin() + 1, args.end());
41  }
42  else
43  mexErrMsgIdAndTxt("mexopencv:error",
44  "Invalid detector arguments");
45  }
46  else
47  mexErrMsgIdAndTxt("mexopencv:error",
48  "Unrecognized option %s", key.c_str());
49  }
50 
51  // Process
52  Mat img1(rhs[0].toMat()),
53  img2(rhs[1].toMat()),
54  H1to2(rhs[2].toMat(CV_64F));
55  vector<KeyPoint> keypoints1(rhs[3].toVector<KeyPoint>()),
56  keypoints2(rhs[4].toVector<KeyPoint>());
57  float repeatability = -1.0f;
58  int correspCount = -1;
59  evaluateFeatureDetector(img1, img2, H1to2, &keypoints1, &keypoints2,
60  repeatability, correspCount, fdetector);
61  plhs[0] = MxArray(repeatability);
62  if (nlhs>1)
63  plhs[1] = MxArray(correspCount);
64 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
STL namespace.
T end(T... args)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void evaluateFeatureDetector(const Mat &img1, const Mat &img2, const Mat &H1to2, std::vector< KeyPoint > *keypoints1, std::vector< KeyPoint > *keypoints2, float &repeatability, int &correspCount, const Ptr< FeatureDetector > &fdetector=Ptr< FeatureDetector >())
cv::Ptr< cv::FeatureDetector > createFeatureDetector(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Factory function for FeatureDetector creation.
#define CV_64F
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
Common definitions for the features2d and xfeatures2d modules.
STL class.
Global constant definitions.
T begin(T... args)
T c_str(T... args)
cv::Mat toMat() const