python-opencv Tutorials 一码人翻译(29)图像处理---- --霍夫圆检测

目标

在这一章,

我们将学习使用Hough变换在图像中找到圆。

我们将看到这些功能:cv.hough圆圈()

import numpy as np
import cv2 as cv

img = cv.imread('th.jpg',0)
img = cv.medianBlur(img,5)
cimg = cv.cvtColor(img,cv.COLOR_GRAY2BGR)

circles = cv.HoughCircles(img,cv.HOUGH_GRADIENT,1,20,
                            param1=60,param2=35,minRadius=0,maxRadius=0)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    # draw the outer circle
    cv.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv.circle(cimg,(i[0],i[1]),2,(0,0,255),3)

cv.imshow('detected circles',cimg)
cv.waitKey(0)
cv.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/qq_41905045/article/details/81708227