LArOpenCV  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
SBCluster.cxx
Go to the documentation of this file.
1 #ifndef __SBCLUSTER_CXX__
2 #define __SBCLUSTER_CXX__
3 
4 #include "SBCluster.h"
5 
6 namespace larcv {
7 
8 
9  void SBCluster::_Configure_(const ::fcllite::PSet &pset)
10  {
11 
12  _dilation_size = pset.get<int> ("DilationSize");
13  _dilation_iter = pset.get<int> ("DilationIterations");
14 
15  _blur_size = pset.get<int> ("BlurSize");
16 
17  _thresh = pset.get<float> ("Thresh");
18  _thresh_maxval = pset.get<float> ("ThreshMaxVal");
19 
20  // _polygon_e = pset.get<double>("PolygonEpsilon");
21  }
22 
24  const ::cv::Mat& img,
25  larcv::ImageMeta& meta)
26  {
27 
28  if ( clusters.size() )
29  throw larbys("This algo can only be executed first in algo chain!");
30 
31 
32  ::cv::Mat sb_img; //(s)mooth(b)inary image
33 
34  //Dilate
35  auto kernel = ::cv::getStructuringElement(cv::MORPH_ELLIPSE,::cv::Size(_dilation_size,_dilation_size));
36  ::cv::dilate(img,sb_img,
37  kernel,::cv::Point(-1,-1),_dilation_iter);
38 
39  //Blur
40  ::cv::blur(sb_img,sb_img,
41  ::cv::Size(_blur_size,_blur_size));
42 
43  //Threshold
44  auto t_value = ::cv::threshold(sb_img,sb_img,
45  _thresh,_thresh_maxval,CV_THRESH_BINARY); //return type is "threshold value?"
46 
47 
48  //Contour finding
49  ContourArray_t ctor_v;
50  std::vector<::cv::Vec4i> cv_hierarchy_v;
51  ctor_v.clear(); cv_hierarchy_v.clear();
52 
53  ::cv::findContours(sb_img,ctor_v,cv_hierarchy_v,
54  CV_RETR_EXTERNAL,
55  CV_CHAIN_APPROX_SIMPLE);
56 
57  //Approximate the polygon curve using Douglas-Peucker algorithm
58 
59  // ContourArray_t ctor_result_v;
60  // ctor_result_v.resize(ctor_v.size());
61 
62  // for( size_t k = 0; k < ctor_v.size(); k++ )
63  // ::cv::approxPolyDP(ctor_v[k], ctor_result_v[k], _polygon_e, true); //true to close the contours
64 
65 
66  // return ctor_result_v;
67  return ctor_v;
68 
69  }
70 
71 }
72 
73 #endif