python - OpenCV 霍夫圆变换检测球体

  重要的是理解霍夫圆变换过程:https://en.wikipedia.org/wiki/Circle_Hough_Transform

import cv2 as cv

im = cv.imread('../result_25k.png', cv.IMREAD_COLOR)
im_gray = cv.cvtColor(im, cv.COLOR_BGR2GRAY)
im2 = cv.medianBlur(im_gray, 5)
circles = cv.HoughCircles(im2, cv.HOUGH_GRADIENT, 2, im_gray.shape[1] / 8, 100, 130, minRadius=0, maxRadius=0)
print(circles)
for i in circles[0, :]:
    cv.circle(im, (i[0], i[1]), 1, (0, 255, 0), 2)
    cv.circle(im, (i[0], i[1]), i[2], (0, 128, 255), 2)
cv.imshow('im', im)
cv.waitKey(0)
cv.destroyAllWindows()
cv.imwrite('../result.png', im)

  opencv 调参没什么意义,仅对我使用的图像有用。

  测试图像:

  图片来源:http://www.kevinbeason.com/smallpt/

猜你喜欢

转载自www.cnblogs.com/darkchii/p/13207833.html