Python+OpenCV:Hough圆检测(Hough Circle Transform)

82 篇文章 20 订阅

Python+OpenCV:Hough圆检测(Hough Circle Transform)

####################################################################################################
# Hough圆检测(Hough Circle Transform)
def lmc_cv_image_hough_circle_transform():
    """
        函数功能: Hough圆检测(Hough Circle Transform)。
    """

    # 读取图像
    image = lmc_cv.imread('D:/99-Research/Python/Image/opencv-logo-white.png', flags=lmc_cv.IMREAD_UNCHANGED)
    rgb_image = lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2RGB)
    gray_image = lmc_cv.cvtColor(rgb_image, lmc_cv.COLOR_RGB2GRAY)
    pyplot.figure('Image Display')
    pyplot.subplot(1, 2, 1)
    pyplot.imshow(rgb_image, cmap='gray')
    pyplot.title('Original Image')
    pyplot.xticks([])
    pyplot.yticks([])

    # Hough圆检测(Hough Circle Transform)
    gray_image = lmc_cv.medianBlur(gray_image, 3)
    cimg = lmc_cv.cvtColor(gray_image, lmc_cv.COLOR_GRAY2BGR)
    circles = lmc_cv.HoughCircles(gray_image, method=lmc_cv.HOUGH_GRADIENT, dp=1, minDist=100,
                                  param1=80, param2=30, minRadius=50, maxRadius=0)
    circles = np.uint16(np.around(circles))
    for i in circles[0, :]:
        # draw the outer circle
        lmc_cv.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2)
        # draw the center of the circle
        lmc_cv.circle(cimg, (i[0], i[1]), 2, (255, 0, 0), 3)
    pyplot.subplot(1, 2, 2)
    pyplot.imshow(cimg, cmap='gray')
    pyplot.title('Hough Circle Transform Image')
    pyplot.xticks([])
    pyplot.yticks([])

    # 根据用户输入保存图像
    if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
        # 销毁窗口
        pyplot.close('all')
    return

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值