Created
September 3, 2019 21:37
-
-
Save pknowledge/9bec0d5d6900d8b86db51dc1cbcdd697 to your computer and use it in GitHub Desktop.
Circle Detection using OpenCV Hough Circle Transform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 as cv | |
img = cv.imread('smarties.png') | |
output = img.copy() | |
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) | |
gray = cv.medianBlur(gray, 5) | |
circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, 1, 20, | |
param1=50, param2=30, minRadius=0, maxRadius=0) | |
detected_circles = np.uint16(np.around(circles)) | |
for (x, y ,r) in detected_circles[0, :]: | |
cv.circle(output, (x, y), r, (0, 0, 0), 3) | |
cv.circle(output, (x, y), 2, (0, 255, 255), 3) | |
cv.imshow('output',output) | |
cv.waitKey(0) | |
cv.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment