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.
相关推荐
唐兴通个人4 分钟前
金融保险银行营销AI数字化转型培训讲师培训老师唐兴通讲金融银保团队险年金险市场销售
大数据·人工智能
视界先声7 分钟前
AIDAv2:重新定义DeFi的AI驱动金融基础设施
人工智能·金融
焦糖码奇朵、10 分钟前
移动通信网络建设-实验2:5G站点选型与设备部署
网络·数据库·人工智能·5g·信号处理·基带工程
l1t11 分钟前
把ITPUB newkid先生编写的Oracle语法数独求解SQL改写成DuckDB
数据库·人工智能·sql·oracle·duckdb
sugarzhangnotes23 分钟前
四大AI相关平台特点分析与对比
人工智能
IT_陈寒37 分钟前
SpringBoot性能优化实战:我从10万QPS项目中总结的7个核心技巧
前端·人工智能·后端
wzx_Eleven38 分钟前
【论文阅读】Towards Fair Federated Learning via Unbiased Feature Aggregation
论文阅读·人工智能·神经网络
星马梦缘39 分钟前
Whole-Body Control——双足机器人全身控制技术 论文阅读笔记
人工智能·机器人·控制·wbc·雅可比·wbosc·机器人全身控制
后端小张40 分钟前
【JAVA 进阶】SpringAI人工智能框架深度解析:从理论到实战的企业级AI应用开发指南
java·开发语言·人工智能
nnn__nnn41 分钟前
哈尔特征:计算机视觉中的经典特征提取范式与现代延伸
人工智能·计算机视觉·目标跟踪