【问题标题】:Zernike moments error on irregular shapes?不规则形状上的 Zernike 矩误差?
【发布时间】:2018-12-01 09:34:53
【问题描述】:

当我在某些包含非常不规则形状的图像上调用 mahotas.features.zernike_moments 时,我收到以下错误:

fv = mahotas.features.zernike_moments(mask, cv2.minEnclosingCircle(cnt)[1], degree=8)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\mahotas\features\zernike.py", line 59, in zernike_moments
    c0,c1 = center_of_mass(im)
ValueError: too many values to unpack (expected 2)

它适用于如下简单的形状:

但我使用以下代码在下图中收到错误。知道我做错了什么吗?

penStrokes = np.array(penStrokes)
peri = cv2.arcLength(penStrokes, True)
approx = cv2.approxPolyDP(penStrokes, 0.02 * peri, True) 
mask = np.zeros((frame.shape[0], frame.shape[1], 1), dtype='uint8')
cv2.drawContours(mask, [approx], -1, (255,), -1)
cnt = cv2.findContours(mask.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[1][0]
cv2.imshow('mask', mask)


# Determine shape from zernike moments
fv = mahotas.features.zernike_moments(mask, cv2.minEnclosingCircle(cnt)[1], degree=8)
print(fv)

编辑 看来如果我将蒙版调整为 500 像素宽,代码是否有效? mahotas 是否有形状所需的最小尺寸?

【问题讨论】:

    标签: python opencv cv2 mahotas


    【解决方案1】:

    这里是mahotas的作者。

    mask 是 3-D 图像(虽然最后一个维度是 1),而该函数仅适用于 1-D 图像。试试:

    fv = mahotas.features.zernike_moments(mask[:,:,0], \
                            cv2.minEnclosingCircle(cnt)[1], \
                            degree=8)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 2011-02-02
      相关资源
      最近更新 更多