如何利用OpenCV测量齿轮尺寸

2024-09-30 18:33:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在进行一个项目,我必须测量齿轮的尺寸。我已经找到了齿轮的轮廓和轮齿。现在我想用100%的精度来测量它的真实尺寸齿轮的真实尺寸是外径53毫米,内径43毫米,齿的尺寸是5毫米,如果我拆下这个齿轮并放置大齿轮,它也会测量它的正确直径

my image is here

# count outer teeth
c = max(max_c, key=cv2.contourArea)
hull = cv2.convexHull(c, clockwise=True, returnPoints=False)
hull1 = []
for i in hull:
    if len(hull1) == 0:
        hull1.append(i)
    else:
        last = hull1[-1]
        diff = c[i] - c[last]
        if cv2.norm(diff) > 10:
            hull1.append(i)
hull1 = np.asarray(hull1)
hull2 = hull1[:-1].copy()

# count inner teeth
defects = cv2.convexityDefects(c, hull2)
#print(defects)
inner_points = []
for i in range(defects.shape[0]):
    s, e, f, d = defects[i, 0]
    far = tuple(c[f][0])
    #print(far)
    inner_points.append(f)

Tags: inforif尺寸countcv2max齿轮