Python 25. opencv 霍夫变换 圆变换 找圆

Python 25. opencv 霍夫变换 圆变换 找圆_第1张图片

import cv2
import numpy as np

img = cv2.imread('logo.png')
img = cv2.medianBlur(img, 5)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200, apertureSize=3)

cimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20,
                           param1=50, param2=30, minRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
    cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
    cv2.circle(img, (i[0], i[1]), 2, (0, 255, 0), 3)

cv2.imshow('circles', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

你可能感兴趣的:(Python,OpenCV,图像学习)