mexopencv  0.1
mex interface for opencv library
findCirclesGrid.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.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<=2);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  bool symmetricGrid = true;
30  bool clustering = false;
31  Ptr<FeatureDetector> blobDetector;
32  for (int i=2; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key=="SymmetricGrid")
35  symmetricGrid = rhs[i+1].toBool();
36  else if (key=="Clustering")
37  clustering = rhs[i+1].toBool();
38  else if (key=="BlobDetector") {
39  if (rhs[i+1].isChar())
40  blobDetector = createFeatureDetector(rhs[i+1].toString(),
41  rhs.end(), rhs.end());
42  else if (rhs[i+1].isCell() && rhs[i+1].numel() >= 2) {
43  vector<MxArray> args(rhs[i+1].toVector<MxArray>());
44  blobDetector = createFeatureDetector(args[0].toString(),
45  args.begin() + 1, args.end());
46  }
47  else
48  mexErrMsgIdAndTxt("mexopencv:error","Invalid arguments");
49  }
50  else
51  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
52  }
53  int flags = (symmetricGrid ? cv::CALIB_CB_SYMMETRIC_GRID :
54  cv::CALIB_CB_ASYMMETRIC_GRID) |
55  (clustering ? cv::CALIB_CB_CLUSTERING : 0);
56  if (blobDetector.empty())
57  blobDetector = SimpleBlobDetector::create();
58 
59  // Process
60  Mat image(rhs[0].toMat(CV_8U));
61  Size patternSize(rhs[1].toSize());
62  vector<Point2f> centers;
63  bool patternFound = findCirclesGrid(image, patternSize, centers, flags,
64  blobDetector);
65  plhs[0] = MxArray(centers);
66  if (nlhs > 1)
67  plhs[1] = MxArray(patternFound);
68 }
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.
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
Common definitions for the features2d and xfeatures2d modules.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.