我想测量圆的圆度("圆"高度和宽度或椭圆参数的差异).圆圈在图片中给出,如下所示:

在做了像color2gray,阈值处理和边界检测之类的常用操作后,我得到如下图所示:

有了这个,我已经尝试了很多不同的东西:

看到这里的代码:
import sys
import cv2
import numpy
from scipy.ndimage import label
# Application entry point
#img = cv2.imread("02_adj_grey.jpg")
img = cv2.imread("fuss02.jpg")
# Pre-processing.
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite("SO_0_gray.png", img_gray)
#_, img_bin = cv2.threshold(img_gray, 0, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY)
_, img_bin = cv2.threshold(img_gray, 170, 255, cv2.THRESH_BINARY)
cv2.imwrite("SO_1_threshold.png", img_bin)
#blur = cv2.GaussianBlur(img,(5,5),0)
img_bin = cv2.morphologyEx(img_bin, cv2.MORPH_CLOSE, numpy.ones((3, 3), dtype=int))
cv2.imwrite("SO_2_img_bin_morphoEx.png", img_bin)
border = img_bin - cv2.erode(img_bin, None)
cv2.imwrite("SO_3_border.png", border)
circles …Run Code Online (Sandbox Code Playgroud) python opencv image-processing feature-detection hough-transform
我看了几页有关在python中使用opencv优化圆检测的页面。所有这些似乎都特定于给定图片的个别情况。cv2.HoughCircles的每个参数有哪些起点?由于我不确定建议的值是多少,因此我尝试了遍历范围,但这并没有产生任何有希望的结果。为什么我无法检测到此图像中的任何圆圈?
import cv2
import numpy as np
image = cv2.imread('IMG_stack.png')
output = image.copy()
height, width = image.shape[:2]
maxWidth = int(width/10)
minWidth = int(width/20)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 20,param1=50,param2=50,minRadius=minWidth,maxRadius=maxWidth)
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circlesRound = np.round(circles[0, :]).astype("int")
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circlesRound:
cv2.circle(output, (x, y), r, (0, 255, 0), …Run Code Online (Sandbox Code Playgroud)