Skip to content

Instantly share code, notes, and snippets.

@squm
Last active July 21, 2017 05:18
Show Gist options
  • Save squm/26fd3b0e184431c0c3a3c89840d73b3e to your computer and use it in GitHub Desktop.
Save squm/26fd3b0e184431c0c3a3c89840d73b3e to your computer and use it in GitHub Desktop.
Mat
hough(Mat src) {
Mat gray;
// cvtColor(src, gray, COLOR_RGB2GRAY);
cvtColor(src, src, COLOR_BGR2RGB);
cvtColor(src, gray, COLOR_RGB2GRAY);
morph_ellipse(gray);
vector<Vec3f> circles;
// minDist Minimum distance between the centers of the detected
// circles. If the parameter is too small, multiple neighbor
// circles may be falsely detected in addition to a true one.
// If it is too large, some circles may be missed.
// param1 it is the higher threshold of the two passed to the Canny
// edge detector (the lower one is twice smaller).
// param2 it is the accumulator threshold for the circle centers at
// the detection stage. The smaller it is, the more false
// circles may be detected. Circles, corresponding to the
// larger accumulator values, will be returned first.
HoughCircles(gray, circles, HOUGH_GRADIENT, 1,
// min distance
// gray.rows / 16,
track3,
// canny1
// 100,
track1 * 2,
// canny1 / 2
// 20,
track2,
// min_radius,
gray.rows / 8 / 8,
// max_radius
gray.rows / 8 / 2
// track3
);
const int thresh = track1;
Canny(gray, src, thresh, thresh * 2, 3);
cvtColor(src, src, COLOR_GRAY2RGB);
for (size_t i = 0; i < circles.size(); i++) {
cv::Scalar color1 = android_green_1;
cv::Scalar color2 = android_blue_1;
const int x = circles[i][0];
const int y = circles[i][1];
const int r = circles[i][2];
cv::Point p = Point(x, y);
circle(src, p, r, color1, 3, LINE_AA);
circle(src, p, 2, color2, 3, LINE_AA);
}
return src;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment