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

时间:2019-07-17 17:36:07

标签: python opencv

我的输入mask是一维灰度图像:

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

它产生一个错误: TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

更新

import cv2

img = cv2.imread('Circles.jpg',0)

print('img.shape', img.shape)
print('img.dtype', img.dtype)

detector = cv2.SimpleBlobDetector_create()

keypoints = detector.detect(img)

print('type(keypoints)', type(keypoints))
print('keypoints', keypoints)

输出:

img.shape (428, 500)
img.dtype uint8
type(keypoints) <class 'list'>
keypoints []

图片:

enter image description here

1 个答案:

答案 0 :(得分:1)

我不知道背景知识,但是在某些时候,创建检测器对象的方式发生了变化。
这应该可以使您的代码正常工作:

detector = cv2.SimpleBlobDetector_create()

Documentation