python 计算圆形度。
如何使用python 计算圆形度
import numpy as np
import cv2 as cv
img = cv.imread(r'D:\PythonProject\QTNLS\analysis\1.png',0)
img = cv.medianBlur(img,5)
cimg = cv.cvtColor(img,cv.COLOR_GRAY2BGR)
circles = cv.HoughCircles(img,cv.HOUGH_GRADIENT,1,20,
param1=300,param2=30,minRadius=20,maxRadius=100)
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()
调试了两个小时的黄金教训:
circles = cv.HoughCircles(image, cv.HOUGH_GRADIENT, 1,50, param1=51, param2=20, minRadius=round(abs(radius-10)), maxRadius=round(abs(radius+10)))
minRadius=round(abs(radius-10)), maxRadius=round(abs(radius+10)) 在两个参数如果选择的合理的话,准确率能到95%以上