3

我正在尝试用形态去除噪音,但内核给了我错误:

import skimage.io as io
import numpy as np
import cv2

c=io.imread('circles.png').astype('bool')*1
x=np.random.random_sample(c.shape)
c[np.nonzero(x>0.95)]= 0
c[np.nonzero(x<=0.05)] = 1

opening = cv2.morphologyEx(c, cv2.MORPH_OPEN, np.ones((2,2),np.uint8))

io.imshow(opening)

错误:

error: OpenCV(4.1.2) C:/projects/opencv-python/opencv/modules/imgproc/src/morph.simd.hpp:756: error: (-213:The function/feature is not implemented) Unsupported data type (=4) in function 'cv::opt_AVX2::getMorphologyRowFilter'
4

1 回答 1

3

您的数据类型 (=4) 是 CV_32SC1,它是 32 位有符号单通道 - 您需要将数据转换为另一种数据类型,我建议使用 CV_8UC1,因为它具有最小的内存占用和易用性:

c = c.astype('uint8') # or c.astype(np.byte)
于 2020-05-04T03:17:37.463 回答