Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv simpleblobdetector - get blob attributes for identified blobs

Tags:

python

opencv

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

like image 821
Peter Avatar asked Dec 08 '16 05:12

Peter


1 Answers

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)
like image 137
Solar.gy Avatar answered Oct 31 '22 20:10

Solar.gy