8

I'm using the simpleblobdetector from opencv with python to identify blobs in an image.

I'm able to get the simple blob detector to work and give me the locations of identified blobs. But can I also get the inertia/convexity/circularity/etc properties of identified blobs?

img = cv2.imread('image.png', cv2.IMREAD_GRAYSCALE)

# set up blob detector params
detector_params = cv2.SimpleBlobDetector_Params()
detector_params.filterByInertia = True
detector_params.minInertiaRatio = 0.001
detector_params.filterByArea = True
detector_params.maxArea = 10000000
detector_params.minArea = 1000
detector_params.filterByCircularity = True
detector_params.minCircularity = 0.0001
detector_params.filterByConvexity = True
detector_params.minConvexity = 0.01

detector = cv2.SimpleBlobDetector_create(detector_params)

# Detect blobs.
keypoints = detector.detect(img)

# print properties of identified blobs
for p in keypoints:
    print(p.pt) # locations of blobs
    # circularity???
    # inertia???
    # area???
    # convexity???
    # etc...

Thanks

1
  • besides p.pt you can also get the p.size, not sure if that helps Commented Sep 27, 2020 at 7:27

1 Answer 1

2

The keypoints returned by the detector do not contain any information about the algorithm that found them, as per opencv.org:

cv::KeyPoint: Data structure for salient point detectors.

The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint detectors, such as Harris corner detector, cv::FAST, cv::StarDetector, cv::SURF, cv::SIFT, cv::LDetector etc.

The keypoint is characterized by the 2D position, scale (proportional to the diameter of the neighborhood that needs to be taken into account), orientation and some other parameters.

You can draw the keypoints, showing size and rotation:

img = cv2.drawKeypoints(img, keypoints, None, color=(0,255,0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Sign up to request clarification or add additional context in comments.

3 Comments

Too bad, it would be helpful in parameterization.
I still cannot wrap my head around all this. Just detecting a blob and it's location might be enough for some scenarios but there are so many others where things like size (in my case I am using the detector to detect pores in a membrane and calculate each pore's diameter) would be very helpful.
I agree with @rbaleksandar this is extremely frustrating since the blob detector clearly computes all these values, but simply doesn't return them. I'd much rather that the blob detector returns the keypoints with all these parameters and then filter them out myself by hand, I know that matlab has this functionality but I'd much rather stay within python ....

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.