Circle Detection with Hough Cirlces

  • Method — currently only cv2.HOUGH_GRADIENT available
  • dp — Inverse ratio of accumulator resolution
  • MinDist — the minimum distance between the center of detected circles
  • param1 — Gradient value used in the edge detection
  • param2 — Accumulator threshold for the HOUGH_GRADIENT method, lower allows more circles to be detected (false positives)
  • minRadius — limits the smallest circle to this size (via radius)
  • MaxRadius — similarly sets the limit for the largest circles
import cv2
import numpy as np
import cv2.cv as cv
image = cv2.imread('images/bottlecaps.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.medianBlur(gray, 5)
circles = cv2.HoughCircles(blur, cv.CV_HOUGH_GRADIENT, 1.5, 10)
for i in circles[0,:]:
# draw the outer circle
cv2.circle(image,(i[0], i[1]), i[2], (255, 0, 0), 2)

# draw the center of the circle
cv2.circle(image, (i[0], i[1]), 2, (0, 255, 0), 5)
cv2.imshow('detected circles', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

--

--

--

Research Intern at ISRO.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

pystiche: A Framework for Neural Style Transfer

What are Recurrent Neural Networks

M2M Day 342: Is this even humanly possible?

Types of Neural Networks -CNN

Hype or hope – are we witnessing a breakthrough in NLP technology?

Sorting Dating Profiles with Machine Learning and Python

Building a Realtime Fraud Detection System

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prishita Kapoor

Prishita Kapoor

Research Intern at ISRO.

More from Medium

8-PUZZLE IMPLEMENTATION USING A-STAR ALGORITHM

Integrating Excel with Python using xlwings

KEPLERSWAP DApp: Features and Functions.

A reverse proxy server accepts a request from the client, forwards it to a backend server, and…