Python cv2.SimpleBlobDetector()需要什么输入?

Python cv2.SimpleBlobDetector()需要什么输入?,python,opencv,Python,Opencv,我的输入掩码是一维灰色图像: detector = cv2.SimpleBlobDetector() print('mask.shape', mask.shape) # print('mask.dtype', mask.dtype) # mask = mask.astype(np.uint8) mask = np.dstack([mask] * 3) print('mask.shape', mask.shape) # print('mask.dtype', mask.dtype) # keyp

我的输入掩码是一维灰色图像:

detector = cv2.SimpleBlobDetector()

print('mask.shape', mask.shape) #
print('mask.dtype', mask.dtype) #
mask = mask.astype(np.uint8)
mask = np.dstack([mask] * 3)
print('mask.shape', mask.shape) #
print('mask.dtype', mask.dtype) #
keypoints = detector.detect(mask)

print('type(keypoints)', type(keypoints))
print('keypoints', keypoints)
输出:

mask.shape (360, 480)
mask.dtype uint8
mask.shape (360, 480, 3)
mask.dtype uint8
img.shape (428, 500)
img.dtype uint8
type(keypoints) <class 'list'>
keypoints []
它会产生一个错误: TypeError:不正确的自我类型必须为“Feature2D”或其派生类型

更新:

输出:

mask.shape (360, 480)
mask.dtype uint8
mask.shape (360, 480, 3)
mask.dtype uint8
img.shape (428, 500)
img.dtype uint8
type(keypoints) <class 'list'>
keypoints []
图片:


我不知道背后的故事,但在某个时候,你创建探测器对象的方式被改变了。 这将使您的代码正常工作:

detector = cv2.SimpleBlobDetector_create()

你说你的面具是1D。但你的错误表明需要2D。请说得更具体些。以什么方式是1D?您的输出看起来像是图像已从灰度1通道变为真彩色3通道。这可能就是问题所在?@mrglud另一种方法是使用cv2.findContours和过滤技术获取每个斑点的轮廓,因为在黑白灰度图像上找不到任何斑点。显然,在灰度图像中,算法使用白色作为背景,并查找非白色斑点。因为当你反转图像时,它会检测到一堆点。要反转图像,请将img=cv2.bitwise_notimg放在img=cv2.imread'Circles.jpg'的正下方,0