import cv2
import numpy as np
# Read image
img = cv2.imread("resulthongdian.png")
# Convert to grayscale
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detect circles in the image
circles = cv2.HoughCircles(gray_img, cv2.HOUGH_GRADIENT, 1, 20, param1 = 50, param2 = 30, minRadius = 0, maxRadius = 0)
# Draw detected circles
if circles is not None:
# Convert the circle parameters a, b and r to integers
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
# Draw outer circle
cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
# Draw inner circle
cv2.circle(img, (i[0], i[1]), 2, (0, 0, 255), 3)
# Print the number of detected circles
print("Number of detected circles:", len(circles[0]))
cv2.imwrite("detected_circles.jpg", img)
用python opencv找图片上的小圆点的个数的代码。
最新推荐文章于 2024-06-11 10:00:18 发布