gpt4 book ai didi

python - 使用openCV和HoughCircles无助地迷失了方向

转载 作者:行者123 更新时间:2023-12-02 17:42:30 29 4
gpt4 key购买 nike

我正在尝试检测此黑色圆圈here。应该不太困难,但是由于某些原因,根据参数,我到处只能得到0个圆或大约500个圆。但是没有中间立场。感觉像我尝试了几个小时的争论,但绝对没有成功。使用HoughCircles和黑白图片是否有问题?肉眼看来,这项任务很简单,但是由于某种原因,这对计算机来说难吗?

这是我的代码:

import numpy as np
import cv2

image = cv2.imread('temp.png')
output = image.copy()
blurred = cv2.blur(image,(10,10))

gray = cv2.cvtColor(blurred, cv2.COLOR_BGR2GRAY)


circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.5, 20, 100, 600, 10, 100)


if circles is not None:

circles = np.round(circles[0, :]).astype("int")
print len(circles)

for (x, y, r) in circles:
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)

show the output image
cv2.imshow("output", np.hstack([output]))
cv2.waitKey(0)

最佳答案

您的方法几乎没有小错误。

这是我从文档中使用的代码:

img = cv2.imread('temp.png',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
cimg1 = cimg.copy()

circles = cv2.HoughCircles img,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,255,255),3)

cv2.imshow('detected circles.jpg',cimg)

enter image description here
joint = np.hstack([cimg1, cimg])  #---Posting the original image along with the image having the detected circle
cv2.imshow('detected circle and output', joint )

enter image description here

关于python - 使用openCV和HoughCircles无助地迷失了方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42654568/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com