17

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?

2
  • What is the image channel? RGB or gray scale? Commented Jan 7, 2018 at 12:19
  • @Saranraj Nambusubramaniyan It is RGB. I've already set filterByColor = True though. Commented Jan 7, 2018 at 12:33

1 Answer 1

47

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Oh! That wasn't obvious at all. Do you know where that's documented? All of the other SO questions I saw use SimpleBlobDetector(params) to create the detector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.