Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. Mat
  2. hough(Mat src) {
  3. Mat gray;
  4.  
  5. // cvtColor(src, gray, COLOR_RGB2GRAY);
  6. cvtColor(src, src, COLOR_BGR2RGB);
  7. cvtColor(src, gray, COLOR_RGB2GRAY);
  8.  
  9. morph_ellipse(gray);
  10.  
  11. vector<Vec3f> circles;
  12.  
  13. // minDist Minimum distance between the centers of the detected
  14. // circles. If the parameter is too small, multiple neighbor
  15. // circles may be falsely detected in addition to a true one.
  16. // If it is too large, some circles may be missed.
  17.  
  18. // param1 it is the higher threshold of the two passed to the Canny
  19. // edge detector (the lower one is twice smaller).
  20.  
  21. // param2 it is the accumulator threshold for the circle centers at
  22. // the detection stage. The smaller it is, the more false
  23. // circles may be detected. Circles, corresponding to the
  24. // larger accumulator values, will be returned first.
  25.  
  26. HoughCircles(gray, circles, HOUGH_GRADIENT, 1,
  27. // min distance
  28. // gray.rows / 16,
  29. track3,
  30.  
  31. // canny1
  32. // 100,
  33. track1 * 2,
  34.  
  35. // canny1 / 2
  36. // 20,
  37. track2,
  38.  
  39. // min_radius,
  40. gray.rows / 8 / 8,
  41.  
  42. // max_radius
  43. gray.rows / 8 / 2
  44. // track3
  45. );
  46.  
  47. const int thresh = track1;
  48. Canny(gray, src, thresh, thresh * 2, 3);
  49.  
  50. cvtColor(src, src, COLOR_GRAY2RGB);
  51.  
  52. for (size_t i = 0; i < circles.size(); i++) {
  53.  
  54. cv::Scalar color1 = android_green_1;
  55. cv::Scalar color2 = android_blue_1;
  56.  
  57. const int x = circles[i][0];
  58. const int y = circles[i][1];
  59. const int r = circles[i][2];
  60.  
  61. cv::Point p = Point(x, y);
  62.  
  63. circle(src, p, r, color1, 3, LINE_AA);
  64. circle(src, p, 2, color2, 3, LINE_AA);
  65. }
  66.  
  67. return src;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement