栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用OpenCV进行圆检测

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用OpenCV进行圆检测

@Carlos,在您所描述的情况下,我并不是Hough
Circles的忠实粉丝。老实说,我发现此算法非常不直观。在您的情况下,我建议使用

findContour()
函数,然后计算质心。因此,我对Hough的参数进行了一些调整以获得合理的结果。在Canny之前,我还使用了另一种预处理方法,因为我看不到该阈值在特定情况下如何在其他情况下起作用。

霍夫法:

寻找群众中心:

和代码:

from matplotlib.pyplot import imshow, scatter, show, savefigimport cv2image = cv2.imread('circles.png', 0)#_, image = cv2.threshold(image, 254, 255, cv2.THRESH_BINARY)image = cv2.GaussianBlur(image.copy(), (27, 27), 0)image = cv2.Canny(image, 0, 130)cv2.imshow("canny", image)cv2.waitKey(0)imshow(image, cmap='gray')circles = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 22, minDist=1, maxRadius=50)x = circles[0, :, 0]y = circles[0, :, 1]scatter(x, y)show()savefig('result1.png')cv2.waitKey(0)_, cnts, _ = cv2.findContours(image.copy(), cv2.RETR_EXTERNAL,    cv2.CHAIN_APPROX_SIMPLE)# loop over the contoursfor c in cnts:    # compute the center of the contour    M = cv2.moments(c)    cX = int(M["m10"] / M["m00"])    cY = int(M["m01"] / M["m00"])    #draw the contour and center of the shape on the image    cv2.drawContours(image, [c], -1, (125, 125, 125), 2)    cv2.circle(image, (cX, cY), 3, (255, 255, 255), -1)cv2.imshow("Image", image)cv2.imwrite("result2.png", image)cv2.waitKey(0)

两种方法都需要进行一些微调,但我希望可以为您提供更多的帮助。

资料来源:这个答案和pyimagesearch。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625909.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号