Hi, I’m not sure where to ask this so if this is the wrong place please point me to the correct one.
But anyways, the OpenCV blob detection in python is extremely frustrating to me because it is nearly useless for the task I need it for and it could be massively improved.
I’m working with images that typically have 4 blobs that I need to detect, but occasionally the images have 5+ blobs and in this case I need to filter out the blobs, but this isn’t really possible with the openCV blob detector because it gives no information besides area and blob center, but the funny thing is the blob detector has the ability to calculate a lot of useful values for determining which 4 blobs are the “best” blobs but those values are inaccessible to the python user because you can only pass parameters to the blob detector that then filters out the blobs before hand but it never returns the useful values so I can filter them out by hand.
To better explain what I mean lets take a concrete example I have 5 blobs in my image with the following circularities: [0.99, 0.89, 0.80, 0.79, 0.75] and I want to get the blobs with the highest circularity. So my only way to do this with the current blob detector is to do it with some kind of brute force like in this pseudocode
blobs = detect(img, min_circularity=0.5) # 5 blobs detected
blobs = detect(img, min_circularity=0.6) # 5 blobs detected
blobs = detect(img, min_circularity=0.7) # 5 blobs detected
blobs = detect(img, min_circularity=0.8) # 3 blobs detected
blobs = detect(img, min_circularity=0.75) # 5 blobs detected
blobs = detect(img, min_circularity=0.77) # 4 blobs detected like we wanted
So we need multiple passes over the image when it could be solved in a single pass if the detector was implemented slightly differently like in the following way:
blobs = detect(img)
blobs = sorted(blobs, key = lambda blob: blobl.circularity)[:4]
I know that matlab does it in a similar way to how I want, but I’d rather not use matlab for anything. Where do I go/what do I do to get this implemented in OpenCV?