Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-openCv检测给出奇怪结果的圆_Python_Opencv_Object Detection - Fatal编程技术网

Python-openCv检测给出奇怪结果的圆

Python-openCv检测给出奇怪结果的圆,python,opencv,object-detection,Python,Opencv,Object Detection,我正在使用中解释的代码,并试图基本上检测显示在instagram示例页面(附件)下半部分的小圆形轮廓图像(精确地说是5)。我不明白的是为什么: 1.代码只捕获了5个小的圆形轮廓圆中的一个 2.为什么页面上有一个大圆圈,我觉得很荒谬。 以下是我正在使用的代码: # we create a copy of the original image so we can draw our detected circles # without destroying the original image. i

我正在使用中解释的代码,并试图基本上检测显示在instagram示例页面(附件)下半部分的小圆形轮廓图像(精确地说是5)。我不明白的是为什么: 1.代码只捕获了5个小的圆形轮廓圆中的一个 2.为什么页面上有一个大圆圈,我觉得很荒谬。 以下是我正在使用的代码:

# we create a copy of the original image so we can draw our detected circles 
# without destroying the original image.
image = cv2.imread("instagram_page.png")

# the cv2.HoughCircles function requires an 8-bit, single channel image, 
# so we’ll convert from the RGB color space to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#blurred = cv2.GaussianBlur(gray, (5, 5), 0)

# detect circles in the image. We pass in the image we want to detect circles as the first argument, 
# the circle detection method as the second argument (currently, the cv2.cv.HOUGH_GRADIENT method 
# is the only circle detection method supported by OpenCV and will likely be the only method for some time),
# an accumulator value of 1.5 as the third argument, and finally a minDist of 100 pixels.
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.7, minDist= 1, param1 = 300, param2 = 100, minRadius=3, maxRadius=150)

print("Circles len -> {}".format(len(circles)))


# ensure at least some circles were found
if circles is not None:    
    # convert the (x, y) coordinates and radius of the circles to integers
    # converting our circles from floating point (x, y) coordinates to integers, 
    # allowing us to draw them on our output image.
    circles = np.round(circles[0, :]).astype("int")

    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        orange = (39, 127, 255)
        cv2.circle(output, (x, y), r, orange, 4)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)


img_name = "Output"
cv2.namedWindow(img_name,cv2.WINDOW_NORMAL)
cv2.resizeWindow(img_name, 800,800)
cv2.imshow(img_name, output)
cv2.waitKey(0)    
cv2.destroyAllWindows()

我使用minDist=1来确保这些紧密的圆圈可能被捕获。有人看到我的参数完全出了问题吗?

我对参数进行了处理,并设法检测到了所有的圆圈(Ubuntu 16.04 LTS x64,Python 3.7,
numpy==1.15.1
Python opencv==3.4.3
):


我反复使用参数并设法检测到所有圆圈(Ubuntu 16.04 LTS x64,Python 3.7,
numpy==1.15.1
Python opencv==3.4.3
):


谢谢您,先生,非常感谢。请问您能否用简单的英语解释一下param1和param2的含义?可能它们是我在公式中唯一不完全理解的两个参数(我查看了官方定义,但我真的不理解)。谢谢,恐怕我对算法也没有足够的了解。我只是一步一步地增加/减少参数,以找到最佳结果。我只知道,
param1
决定了边缘检测算法的灵敏度,
param2
决定了我看到的中心检测算法的灵敏度。你的解决方案很有帮助,但我在另一个instagram页面上进行了测试,结果显示页面上有30多个随机圆圈。我不明白为什么这个库如此不稳定,特别是当涉及到识别网页上的清晰对象时,你必须深入到理论和库源代码才能理解这一点。您也可以在dsp.stackexchange.com上发布问题,因为这实际上不再是简单的编码。但是如果你不想走那么远,你可以尝试一些预处理方法,比如过滤和额外的边缘检测。谢谢你,先生,谢谢。请问您能否用简单的英语解释一下param1和param2的含义?可能它们是我在公式中唯一不完全理解的两个参数(我查看了官方定义,但我真的不理解)。谢谢,恐怕我对算法也没有足够的了解。我只是一步一步地增加/减少参数,以找到最佳结果。我只知道,
param1
决定了边缘检测算法的灵敏度,
param2
决定了我看到的中心检测算法的灵敏度。你的解决方案很有帮助,但我在另一个instagram页面上进行了测试,结果显示页面上有30多个随机圆圈。我不明白为什么这个库如此不稳定,特别是当涉及到识别网页上的清晰对象时,你必须深入到理论和库源代码才能理解这一点。您也可以在dsp.stackexchange.com上发布问题,因为这实际上不再是简单的编码。但是如果你不想走那么远,你可以尝试一些预处理方法,比如过滤和附加的边缘检测
circles = cv2.HoughCircles(
    gray,
    cv2.HOUGH_GRADIENT,
    1.7,
    minDist=100,
    param1=48,
    param2=100,
    minRadius=2,
    maxRadius=100
)