TypeError:使用Otsu阈值

时间:2018-06-18 21:42:34

标签: python feature-extraction threshold

我尝试应用像Otsu阈值那样的预处理过滤器,然后通过特征提取算法来传递特征提取算法。

我收到错误

TypeError: bad argument type for built-in operation

在第

im = cv2.imread(img, 0)

这是代码

def featurestest (img):
# Otsu's thresholding


im = cv2.imread(img, 0)
ret2, imgf = cv2.threshold(im, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)

# image skeltonized

size = np.size(imgf)
skel = np.zeros(imgf.shape, np.uint8)

# ret, img = cv2.threshold(img, 127, 255, 0)
element = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))
done = False

while (not done):
    eroded = cv2.erode(imgf, element)
    temp = cv2.dilate(eroded, element)
    temp = cv2.subtract(imgf, temp)
    skel = cv2.bitwise_or(skel, temp)
    imgf = eroded.copy()

    zeros = size - cv2.countNonZero(imgf)
    if zeros == size:
        done = True


# skew and kurtosis

skew = scipy.stats.skew(imgf)
kurt = scipy.stats.kurtosis(imgf)

完整的错误消息

im = cv2.imread(img, 0)
TypeError: bad argument type for built-in operation

0 个答案:

没有答案