Circle Detection Program using Hough Transform
- Login to Download
- 1 Credits
Resource Overview
Hough Transform is a powerful tool for detecting lines and circles in image processing, featuring a comprehensive implementation example for circle detection with detailed code explanations.
Detailed Documentation
Although Hough Transform is a powerful tool for detecting lines and circles, it is not universally applicable. Therefore, proper image preprocessing must be performed before applying Hough Transform to enhance detection accuracy. When detecting circles using Hough Transform, understanding the radius range is particularly important for specific applications. The following example program demonstrates circle detection using Hough Transform, serving as a reference to better understand its practical implementation.
The code utilizes OpenCV's HoughCircles function which employs the Hough gradient method for circle detection. Key implementation steps include:
- Loading and preprocessing the input image with median blurring to reduce noise
- Converting grayscale image to BGR color space for visualization purposes
- Configuring Hough transform parameters including detection sensitivity (param1), accumulation threshold (param2), and radius constraints
import cv2
import numpy as np
img = cv2.imread('circle.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
The algorithm works by accumulating votes in a 3D parameter space (x-center, y-center, radius) and identifying local maxima corresponding to circle candidates. Detected circles are visualized with green boundaries and red center points, providing clear visual feedback for verification.
- Login to Download
- 1 Credits