I'm trying to run blob detection using some simple code:
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)
However I keep getting the following error:
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)
Does anyone know what might be wrong?
If your OpenCV version is 2.x
, then use cv2.SimpleBlobDetector()
. Otherwise if your OpenCV version 3.x (or 4.x)
, then use cv2.SimpleBlobDetector_create
to create the detector.
## 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With