|

楼主 |
发表于 2024-5-7 19:45:43
|
显示全部楼层
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread('E:/pythonpictures/5.jpg', 0)
img = cv.medianBlur(img, 5)
cimg = cv.cvtColor(img, cv.COLOR_GRAY2BGR)
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, minDist=30, param1=100, param2=50, minRadius=0, maxRadius=200)
print('circles1:', circles)
circles = np.uint16(np.around(circles))
print('circles2:', circles)
for i in circles[0, :]:
# draw the outer circle
cv.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2)
# draw the center of the circle
cv.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)
plt.figure(figsize=(10, 8), dpi=100)
plt.imshow(cimg[:, :, ::-1])
plt.xticks([]), plt.yticks([])
plt.show()
霍夫变换圆识别程序 |
|