Circles can be detected in OpenCV using the HoughCircles function. This function uses the Hough transform to detect circles in images based on their edge information.
Here's an example of how to use the HoughCircles function to detect circles in an image:
import cv2
import numpy as np
# Load image
img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
# Blur image to reduce noise and improve circle detection
img = cv2.medianBlur(img, 5)
# Detect circles using Hough transform
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
# Draw circles on original image
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(img, (x, y), r, (0, 255, 0), 2)
cv2.circle(img, (x, y), 2, (0, 0, 255), 3)
# Display result
cv2.imshow('Detected Circles', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
In this example, the HoughCircles function is called with several parameters:
The circles are then drawn on the original image using the cv2.circle function. The resulting image shows the detected circles in green.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-06-28 11:00:00 +0000
Seen: 17 times
Last updated: Apr 09 '21
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?
What steps can I take to prevent my webpage from slowing down when all parts of a div are displayed?
What is the method to determine the most precise categorization of data using Self Organizing Map?
What causes certain images included in an email to fail to load on iPhone/iPad/iOS?