mexopencv  0.1
mex interface for opencv library
HoughPoint2Line.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/ximgproc.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::ximgproc;
13 
14 namespace {
16 const ConstMap<string, int> AngleRangeOptionMap = ConstMap<string, int>
17  ("ARO_0_45", cv::ximgproc::ARO_0_45)
18  ("ARO_45_90", cv::ximgproc::ARO_45_90)
19  ("ARO_90_135", cv::ximgproc::ARO_90_135)
20  ("ARO_315_0", cv::ximgproc::ARO_315_0)
21  ("ARO_315_45", cv::ximgproc::ARO_315_45)
22  ("ARO_45_135", cv::ximgproc::ARO_45_135)
23  ("ARO_315_135", cv::ximgproc::ARO_315_135)
24  ("ARO_CTR_HOR", cv::ximgproc::ARO_CTR_HOR)
25  ("ARO_CTR_VER", cv::ximgproc::ARO_CTR_VER);
26 
28 const ConstMap<string, int> HoughDeskewOptionMap = ConstMap<string, int>
29  ("Raw", cv::ximgproc::HDO_RAW)
30  ("Deskew", cv::ximgproc::HDO_DESKEW);
31 
33 const ConstMap<string, int> RulesOptionMap = ConstMap<string, int>
34  ("Strict", cv::ximgproc::RO_STRICT)
35  ("IgnoreBorders", cv::ximgproc::RO_IGNORE_BORDERS);
36 }
37 
45 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
46 {
47  // Check the number of arguments
48  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
49 
50  // Argument vector
51  vector<MxArray> rhs(prhs, prhs+nrhs);
52 
53  // Option processing
54  int angleRange = cv::ximgproc::ARO_315_135;
55  int makeSkew = cv::ximgproc::HDO_DESKEW;
56  int rules = cv::ximgproc::RO_IGNORE_BORDERS;
57  for (int i=2; i<nrhs; i+=2) {
58  string key(rhs[i].toString());
59  if (key == "AngleRange")
60  angleRange = AngleRangeOptionMap[rhs[i+1].toString()];
61  else if (key == "MakeSkew")
62  makeSkew = HoughDeskewOptionMap[rhs[i+1].toString()];
63  else if (key == "Rules")
64  rules = RulesOptionMap[rhs[i+1].toString()];
65  else
66  mexErrMsgIdAndTxt("mexopencv:error",
67  "Unrecognized option %s", key.c_str());
68  }
69 
70  // Process
71  Point houghPoint(rhs[0].toPoint());
72  Mat src(rhs[1].toMat());
73  Vec4i line = HoughPoint2Line(houghPoint, src, angleRange, makeSkew, rules);
74  plhs[0] = MxArray(line);
75 }
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.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.