我用下面的代码来检测圆圈:
gray = cv2.GaussianBlur(gray, (5, 5), 0);
gray = cv2.medianBlur(gray, 5)
kernel = np.ones((2, 2), np.uint8)
gray = cv2.erode(gray, kernel, iterations=1)
gray = cv2.dilate(gray, kernel, iterations=1)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 200,
param1=100, param2=50, minRadius=0, maxRadius=150)
if circles is not None:
# Convert the (x,y) coordinate and radius of the circles
circles = np.round(circles[0, :]).astype("int")
# Loop over the (x,y) coordinate and radius of the circles
for (x, y, r) in circles:
# Draw the circle in the output
cv2.circle(fancy_frame, (x+x1, y+y1), r, (0, 255, 0), 4)
然而,当我发现圆圈在跳跃。我怎样才能解决这个问题?有没有haar或svm来检测它?在
这是我得到的输出:
[![输出][1]][1]
我要在实时视频中检测所有的圆圈
你的代码看起来不错,很可能你只需要调整一下^{} parameters 。在
从降低
dp
参数开始,它应该可以提供更多的检测。我跑了houghcircles.py从图像上的OpenCV samples文件夹中,它可以检测到其余大多数圆:圆的Hough检测计算量很大,所以很难实时运行。此外,你的图像上的“圆圈”还远远不够完美,这不利于算法的实现。考虑训练一个神经网络来检测这些特征。在
相关问题 更多 >
编程相关推荐