Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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 - Fatal编程技术网

Python 如何在一幅图像中将多个相连的圆分割成单个圆?

Python 如何在一幅图像中将多个相连的圆分割成单个圆?,python,opencv,image-processing,Python,Opencv,Image Processing,我已经将原始图像处理为二进制图像。给你。 这是经过处理的二值图像。 这是我的源代码 import cv2 import numpy as np img = cv2.imread("keli.jpg") gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) cv2.imshow("org",img) ret, thresh = cv2.threshold(gray,200,255,cv2.THRESH_TOZERO_INV) ret1, thresh1 =

我已经将原始图像处理为二进制图像。给你。

这是经过处理的二值图像。

这是我的源代码

import cv2
import numpy as np

img = cv2.imread("keli.jpg")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow("org",img)
ret, thresh = cv2.threshold(gray,200,255,cv2.THRESH_TOZERO_INV)
ret1, thresh1 = cv2.threshold(thresh,40,255,cv2.THRESH_BINARY)
cv2.imshow("thresh",thresh1)

cv2.waitKey(0)
cv2.destroyAllWindows()
现在我尝试检测这张图像中的所有圆,但有一个问题,我不能将它们分割成单个圆。我已经尝试使用边缘检测、腐蚀和放大来处理这张图像,但效果不够好。
那么,有什么好的方法可以解决这个问题。

您尝试过对原始图像进行边缘检测吗?也许不使用canny,但尝试使用梯度提取来获得对图像数据的一些感觉。我已经尝试使用sobel边缘检测圆,但我认为这不足以准确检测所有圆。如何计算被边缘遮挡的圆?不使用它们?你知道或者你能在不检测所有圆的情况下确定近似的平均圆大小吗?看起来所有的圆都有相似的大小,所以不会有比这些圆大/小得多的真实圆了?如果你知道近似的平均圆大小,你可能可以看得更靠近图像/遮罩。因为你的蒙版是好的,如果你的二元蒙版中有蒙版但没有被圆覆盖的区域,你会知道仍然有圆丢失。