A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/circle-detection-using-opencv-python/ below:

Circle Detection using OpenCV | Python

Circle Detection using OpenCV | Python

Last Updated : 11 Aug, 2025

Circle detection is a powerful computer vision technique with applications in fields like biomedicine (e.g., detecting iris in an eye or identifying white blood cells), robotics, quality inspection and object tracking.

OpenCV provides Hough Circle Transform, an algorithm similar to line detection but adapted to identify circular shapes.

Basics of Circle Detection

A circle can be described by the following equation:

A circle in a 2D image has three parameters:

If we fix a point (x, y) on an image, finding a circle involves searching for (h, k, r) in a 3D search space.

The classical Hough Transform for Circles:

OpenCV’s HoughCircles() Function

Instead of manually filling a 3D matrix, OpenCV uses an optimized approach called HOUGH_GRADIENT, which leverages edge gradients for much faster circle detection.

Function Syntax:
cv2.HoughCircles(image, method, dp, minDist, param1=100, param2=100, minRadius=0, maxRadius=0)

Parameters:

Example: Detecting Circles in an Eye Image Python
import cv2
import numpy as np

# Read image
img = cv2.imread("eyes.jpg")
output = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Reduce noise
gray = cv2.medianBlur(gray, 5)

# Detect circles
circles = cv2.HoughCircles(
    gray,
    cv2.HOUGH_GRADIENT,
    dp=1,
    minDist=100,      
    param1=100,         
    param2=40,       
    minRadius=30,       
    maxRadius=60
)

# Draw only the first detected circle
if circles is not None:
    circles = np.uint16(np.around(circles))
    x, y, r = circles[0][0]
    cv2.circle(output, (x, y), r, (0, 255, 0), 2)  # Circle outline
    cv2.circle(output, (x, y), 2, (0, 0, 255), 3)  # Center point

# Show result
cv2.imshow('Detected Circle', output)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output

Explanation:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4