mexopencv  0.1
mex interface for opencv library
FastHoughTransform.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 
29  ("Minimum", cv::ximgproc::FHT_MIN)
30  ("Maximum", cv::ximgproc::FHT_MAX)
31  ("Addition", cv::ximgproc::FHT_ADD)
32  ("Average", cv::ximgproc::FHT_AVE);
33 
35 const ConstMap<string, int> HoughDeskewOptionMap = ConstMap<string, int>
36  ("Raw", cv::ximgproc::HDO_RAW)
37  ("Deskew", cv::ximgproc::HDO_DESKEW);
38 }
39 
47 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
48 {
49  // Check the number of arguments
50  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
51 
52  // Argument vector
53  vector<MxArray> rhs(prhs, prhs+nrhs);
54 
55  // Option processing
56  int dstMatDepth = CV_32S;
57  int angleRange = cv::ximgproc::ARO_315_135;
58  int op = cv::ximgproc::FHT_ADD;
59  int makeSkew = cv::ximgproc::HDO_DESKEW;
60  for (int i=1; i<nrhs; i+=2) {
61  string key(rhs[i].toString());
62  if (key == "DDepth")
63  dstMatDepth = (rhs[i+1].isChar()) ?
64  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
65  else if (key == "AngleRange")
66  angleRange = AngleRangeOptionMap[rhs[i+1].toString()];
67  else if (key == "Op")
68  angleRange = HoughOpMap[rhs[i+1].toString()];
69  else if (key == "MakeSkew")
70  makeSkew = HoughDeskewOptionMap[rhs[i+1].toString()];
71  else
72  mexErrMsgIdAndTxt("mexopencv:error",
73  "Unrecognized option %s", key.c_str());
74  }
75 
76  // Process
77  Mat src(rhs[0].toMat()), dst;
78  FastHoughTransform(src, dst, dstMatDepth, angleRange, op, makeSkew);
79  plhs[0] = MxArray(dst);
80 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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