其他分享
首页 > 其他分享> > OpenCV霍夫圈变换

OpenCV霍夫圈变换

作者:互联网

主要使用cv.HoughCircles()函数来实现。

cv2.HoughCircles(image,method,dp,minDist[, circles[,param1, param2[,minRadius[,maxRadius]]]]])

参数如下:

代码示例:

import numpy as np
import cv2 as cv
img_gray = cv.imread("C:\\Users\\dell\\Desktop\\prac files\\logo1.jpg", 0)
img_gray = cv.medianBlur(img_gray, 5)
img = cv.cvtColor(img_gray, cv.COLOR_GRAY2BGR)
circles = cv.HoughCircles(img_gray, cv.HOUGH_GRADIENT, 1, 200, None, 100, 150, 0, 0)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
    # 绘制外圆
    cv.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
    # 绘制圆心
    cv.circle(img, (i[0], i[1]), 2, (0, 0, 255), 3)
cv.imshow('prac', img)
cv.waitKey(0)
cv.destroyAllWindows()

标签:circles,gray,img,变换,分辨率,霍夫圈,OpenCV,cv,dp
来源: https://blog.csdn.net/weixin_44796581/article/details/120206433