choughcirclesdemo.cpp
Go to the documentation of this file.
1 #include "choughcirclesdemo.h"
2 
3 CHoughCircles::CHoughCircles(int CannyLowThreshold,
4  int CannyHighThreshold,
5  int CirclesToExtract,
6  int minRadius,
7  int maxRadius)
8 {
9  m_nCannyLowThreshold = CannyLowThreshold;
10  m_nCannyHighThreshold = CannyHighThreshold;
11  m_nCirclesToExtract = CirclesToExtract;
12  m_nMinRadius = minRadius;
13  m_nMaxRadius = maxRadius;
14 }
15 
16 //origin image should be gray and then blurred by gauss filter
17 void
18 CHoughCircles::HoughSaliency(CByteImage* origin,
19  CByteImage* saliencyImage,
20  int sampleWindowsize,
21  int width,
22  int height,
23  int windowCenterX,
24  int windowCenterY)
25 {
26  CVec3dArray resultListCircles(50);
27  CDynamicArrayTemplate<int> resultHits(50);
28  CVec2dArray edgePoints(10000), edgeDirections(10000);
29  CByteImage visualizationImage(sampleWindowsize, sampleWindowsize, CByteImage::eRGB24);
30 
31  // detect edges with Canny edge detector
32  ImageProcessor::Canny(
33  origin, edgePoints, edgeDirections, m_nCannyLowThreshold, m_nCannyHighThreshold);
34 
35  // detect circles with Hough transform
36  ImageProcessor::HoughTransformCircles(edgePoints,
37  edgeDirections,
38  sampleWindowsize,
39  sampleWindowsize,
40  m_nMinRadius,
41  m_nMaxRadius,
42  m_nCirclesToExtract,
43  1,
44  resultListCircles,
45  resultHits,
46  &visualizationImage);
47 
48  Vec3d circle = resultListCircles[0];
49 
50  for (int i = 0; i < resultListCircles.GetSize(); i++)
51  {
52  circle = resultListCircles[i];
53  //std::cout << "the center of the circle is:" << circle.x << " " << circle.y << std::endl;
54  circle.x += windowCenterX - sampleWindowsize / 2;
55  circle.y += windowCenterY - sampleWindowsize / 2;
56  if (circle.x >= 0 && circle.y >= 0 && circle.x < width && circle.y < height)
57  {
58  saliencyImage->pixels[(int)circle.y * width + (int)circle.x]++;
59  }
60  }
61 }
62 
63 void
65  CByteImage* saliencyImage,
66  int sampleWindowsize,
67  int width,
68  int height,
69  int windowCenterX,
70  int windowCenterY)
71 {
72  cv::Mat src(origin->height, origin->width, CV_8UC1);
73  std::vector<cv::Vec3f> resultListCircles;
74  std::string path;
75 
76  for (int i = 0; i < src.rows; i++)
77  {
78  for (int j = 0; j < src.cols; j++)
79  {
80  src.at<uint8_t>(i, j) = origin->pixels[i * src.cols + j];
81  }
82  }
83 
84  cv::HoughCircles(src,
85  resultListCircles,
86  cv::HOUGH_GRADIENT,
87  1,
88  src.rows / 8,
89  m_nCannyHighThreshold,
90  20,
91  m_nMinRadius,
92  m_nMaxRadius);
93  if (!resultListCircles.size())
94  {
95  return;
96  }
97  cv::Vec3d circle = resultListCircles[0];
98  for (size_t i = 0; i < resultListCircles.size(); i++)
99  {
100  circle = resultListCircles[i];
101  circle[0] += windowCenterX - sampleWindowsize / 2;
102  circle[1] += windowCenterY - sampleWindowsize / 2;
103  if (circle[0] > 0 && circle[1] > 0 && circle[0] < width - 1 && circle[1] < height - 1)
104  {
105  for (int j = -1; j <= 1; j++)
106  {
107  for (int k = -1; k <= 1; k++)
108  {
109  saliencyImage->pixels[((int)circle[1] + j) * width + ((int)circle[0] + k)] =
110  255;
111  }
112  }
113  }
114  }
115 }
CHoughCircles::openCVHoughSaliency
void openCVHoughSaliency(CByteImage *origin, CByteImage *saliencyImage, int sampleWindowsize, int width, int height, int windowCenterX, int windowCenterY)
Definition: choughcirclesdemo.cpp:64
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
CHoughCircles::HoughSaliency
void HoughSaliency(CByteImage *origin, CByteImage *saliencyImage, int sampleWindowsize, int width, int height, int windowCenterX, int windowCenterY)
Definition: choughcirclesdemo.cpp:18
CHoughCircles::CHoughCircles
CHoughCircles(int CannyLowThreshold=50, int CannyHighThreshold=200, int CirclesToExtract=1, int minRadius=20, int maxRadius=100)
Definition: choughcirclesdemo.cpp:3
choughcirclesdemo.h