OpenCV官方教程中文版 —— Hough 圆环变换

OpenCV官方教程中文版 ------ Hough 圆环变换

  • 前言
  • [Hough 圆环变换](#Hough 圆环变换)

前言

目标

学习使用霍夫变换在图像中找圆形(环)

学习函数:cv2.HoughCircles()

Hough 圆环变换


opencv_logo.png

python 复制代码
# -*- coding: utf-8 -*-
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('opencv_logo.png', 0)
img = cv2.medianBlur(img, 5)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20,
                           param1=50, param2=40, minRadius=0, maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
    # draw the outer circle
    cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2)
    # draw the center of the circle
    cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)

plt.figure()
plt.subplot(121)
plt.imshow(img, cmap='gray')
plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
plt.subplot(122)
plt.imshow(cimg, cmap='gray')
plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
plt.show()
# Python: cv2.HoughCircles(image, method, dp, minDist, circles, param1, param2, minRadius, maxRadius)
# Parameters:
# image -- 8-bit, single-channel, grayscale input image.
# 返回结果为 Output vector of found circles. Each vector is encoded as a
# 3-element floating-point vector (x, y, radius) .
# circle_storage -- In C function this is a memory storage that will contain
# the output sequence of found circles.
# method -- Detection method to use. Currently, the only implemented method is
# CV_HOUGH_GRADIENT , which is basically 21HT , described in [Yuen90].
# dp -- Inverse ratio of the accumulator resolution to the image resolution.
# For example, if dp=1 , the accumulator has the same resolution as the input image.
# If dp=2 , the accumulator has half as big width and height.
# minDist -- Minimum distance between the centers of the detected circles.
# If the parameter is too small, multiple neighbor circles may be falsely
# detected in addition to a true one. If it is too large, some circles may be missed.
# param1 -- First method-specific parameter. In case of CV_HOUGH_GRADIENT ,
# it is the higher threshold of the two passed to the Canny() edge detector
# (the lower one is twice smaller).
# param2 -- Second method-specific parameter. In case of CV_HOUGH_GRADIENT ,
# it is the accumulator threshold for the circle centers at the detection stage.
# The smaller it is, the more false circles may be detected. Circles,
# corresponding to the larger accumulator values, will be returned first.
# minRadius -- Minimum circle radius.
# maxRadius -- Maximum circle radius.
相关推荐
青春不败 177-3266-0520几秒前
最新AI-Python自然科学领域机器学习与深度学习技术——随机森林、XGBoost、CNN、LSTM、Transformer,从数据处理到时空建模等
人工智能·深度学习·机器学习·transformer·自然科学随机森林
yhdata10 分钟前
精准锚定2032!全自动移液机器人市场规模预计突破97.8亿元
人工智能·机器人
人工智能AI技术14 分钟前
深圳千人排队装龙虾太蠢?用C#写个自动化部署脚本,5分钟静默养虾不香吗
人工智能
新科技事物15 分钟前
AI编曲软件提升出歌效率,原创音乐人凭清唱歌词的音频快速作编曲伴奏成歌
人工智能·音视频
小陈phd31 分钟前
多模态大模型学习笔记(十三)——transformer学习之位置编码
人工智能·笔记·transformer
ghie909040 分钟前
基于MATLAB的A*算法避障路径规划实现
人工智能·算法·matlab
IT_陈寒1 小时前
JavaScript 性能优化的5个隐藏技巧:90%开发者都不知道的实战方案!
前端·人工智能·后端
知智前沿1 小时前
OpenClaw 自定义 Skill 开发实战:从零搭建 AI 自动化办公工具
人工智能·microsoft
无巧不成书02181 小时前
全球首款,百度红手指Operator上线 手机AI Agent实操指南
人工智能·百度·智能手机
gaosushexiangji1 小时前
高速3D-DIC在凝灰岩干湿循环损伤演化研究中的应用
图像处理·计算机视觉