我正在尝试使用霍夫圆来检测图像中的刻度盘,但是未检测到这些圆。我使用了以下参数。
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 16, 100, param2=450, minRadius=50, maxRadius=50)
这是我几乎没有调整任何参数的结果:我必须将您的图片缩小到1/3才能运行我的代码,但是
尝试使用houghcircles函数的参数来改善结果
https://docs.opencv.org/2.4/modules/imgproc/doc/feature_detection.html?highlight=houghcircles使用的代码:
import cv2
import numpy as np
def viewImage(image):
cv2.namedWindow('Display', cv2.WINDOW_NORMAL)
cv2.imshow('Display', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
img = cv2.imread('circle.JPG')
im = img.copy()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 0.7, 120)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
# loop and draw detected circle
for (x, y, r) in circles:
cv2.circle(im, (x, y), r, (0, 255, 0), 4)
viewImage(im)