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