python - 了解 Python OpenCV (cv2) 中的 HoughCircles
问题描述
我正在使用此代码,链接代码字体
import cv2
import numpy as np
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=30,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)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
可能很容易,但有人可以帮助我理解 for 循环吗?
谢谢!
解决方案
每个i
infor i in circles[0,:]:
都是一个代表一个圆圈的列表。i
由三个值组成:中心的 x 坐标、中心的 y 坐标和半径。
如果您查看文档,cv2.circle
您将看到如何使用中心和半径来绘制圆。
推荐阅读
- amazon-web-services - 摆脱冻结/挂起的 AWS CLI SSM 会话
- angular - ng-multiselect-dropdown 自定义过滤器
- r - 如何成功加载rnotebook?
- bash - 移动目录中少于 X 行的所有文件
- c# - 如何使用嵌套 if 条件优化方法
- eclipse - Eclipse CDT 不适用于 macOS Monterey
- robocopy - ROBOCOPY:抑制除 PROGRESS BAR 之外的所有输出
- javascript - 无法将信息发送到 Outlook 加载项中的对话框
- laravel - 如何使用 respondToAccessTokenRequest (Passport) Laravel 进行单元测试
- azure - 将 MATLAB 模型集成到 Azure