Skip to content

Instantly share code, notes, and snippets.

@lindskogen
Created June 26, 2017 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindskogen/93d2c9dc8d62a23d0fb4bc7b25e8587f to your computer and use it in GitHub Desktop.
Save lindskogen/93d2c9dc8d62a23d0fb4bc7b25e8587f to your computer and use it in GitHub Desktop.
ML circle detection
# 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