Created
June 26, 2017 16:32
-
-
Save lindskogen/93d2c9dc8d62a23d0fb4bc7b25e8587f to your computer and use it in GitHub Desktop.
ML circle detection
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
# Standard imports | |
import cv2 | |
import numpy as np | |
# Read image | |
img = cv2.imread("IMG_20170624_152655.jpg", 0) | |
img = cv2.medianBlur(img, 5) | |
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) | |
# Set up the detector with default parameters. | |
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20) | |
# cv2.HoughCircles(image, method, dp, minDist, circles, param1, param2, minRadius, maxRadius) | |
# [x, y, radius] | |
circles = np.uint16(np.around(circles)) | |
for circ in circles[0, :]: | |
cv2.circle(cimg, (circ[0], circ[1]), circ[2], (0, 0, 255), 2) | |
# Show keypoints | |
cv2.imshow("Keypoints", cimg) | |
cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment