Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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 图像中重叠噪声圆的检测_Python_Opencv_Image Processing_Image Recognition - Fatal编程技术网

Python 图像中重叠噪声圆的检测

Python 图像中重叠噪声圆的检测,python,opencv,image-processing,image-recognition,Python,Opencv,Image Processing,Image Recognition,我试图识别下图中的两个区域。内部的区域以及外部和内部之间的区域——使用python openCV的边界圆 我尝试了不同的方法,比如: 那不太合适 这在经典图像处理中是可能的,还是我需要一些神经网络 编辑: 测试图像: 一般错误:使用HoughCircles时,应适当选择参数。我发现您在代码中只使用了前4个参数。Ypu可以通过检查了解这些参数 有经验的想法:在使用HoughCircles时,我注意到如果两个圆的两个中心相同或几乎彼此接近,HoughCircles无法检测到它们。即使将“最小距离”参

我试图识别下图中的两个区域。内部的区域以及外部和内部之间的区域——使用python openCV的边界圆

我尝试了不同的方法,比如:

那不太合适

这在经典图像处理中是可能的,还是我需要一些神经网络

编辑:

测试图像:

一般错误:使用HoughCircles时,应适当选择参数。我发现您在代码中只使用了前4个参数。Ypu可以通过检查了解这些参数

有经验的想法:在使用HoughCircles时,我注意到如果两个圆的两个中心相同或几乎彼此接近,HoughCircles无法检测到它们。即使将“最小距离”参数指定给一个小值。在你的例子中,圆心也是一样的

我的建议是:我将为这两个圆的代码附加适当的参数。由于上面解释的问题,我找不到两个带一个参数列表的圆。我的建议是,对同一幅图像应用这两个参数两倍,只需得到圆,就可以得到结果

对于外圈结果和包含的参数代码:

结果:

对于内圈,参数为:

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT,1, rows / 8,
                                   param1=100, param2=30,
                                   minRadius=100, maxRadius=200)
结果:


你能分享你声称houghcircle不工作的代码吗?可能应该是关于参数选择的。当然,你不需要一个神经网络来完成这个简单的任务,这几乎是源代码,但我更新了答案。非常感谢。
# import the necessary packages
import numpy as np
import argparse
import cv2
from PIL import Image

# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread('image.jpg')
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

gray = cv2.medianBlur(gray,15)
rows = gray.shape[0]

# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT,1, rows / 8,
                               param1=100, param2=30,
                               minRadius=200, maxRadius=260)
# ensure at least some circles were found
if circles is not None:
    # convert the (x, y) coordinates and radius of the circles to integers
    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
        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
    img = Image.fromarray(image)
    if img.height > 1500:
        imS = cv2.resize(np.hstack([image, output]), (round((img.width * 2) / 3), round(img.height / 3)))
    else:
        imS = np.hstack([image, output])
    # Resize image
    cv2.imshow("gray", gray)
    cv2.imshow("output", imS)
    cv2.waitKey(0)
else:
    print("No circle detected")
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT,1, rows / 8,
                                   param1=100, param2=30,
                                   minRadius=100, maxRadius=200)