我正在尝试使用一些简单的代码运行斑点检测:
img = cv2.imread(args["image"])
height, width, channels = img.shape
params = cv2.SimpleBlobDetector_Params()
params.filterByColor = True
params.blobColor = 0
blob_detector = cv2.SimpleBlobDetector(params)
keypoints = blob_detector.detect(img)
但是我不断收到以下错误:
Traceback (most recent call last):
File "test2.py", line 37, in <module>
keypoints = blob_detector.detect(img)
TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)
有谁知道可能出了什么问题?
如果您的 OpenCV 版本是2.x
,然后使用cv2.SimpleBlobDetector()
。否则如果你的 OpenCV 版本3.x (or 4.x)
,然后使用cv2.SimpleBlobDetector_create
创建探测器。
## check opencv version and construct the detector
is_v2 = cv2.__version__.startswith("2.")
if is_v2:
detector = cv2.SimpleBlobDetector()
else:
detector = cv2.SimpleBlobDetector_create()
## detect
kpts = detector.detect(img)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)