3

I want to get some descriptors for each white area on image to filter that areas and operate with them separately. How can I do it?

I have read How to use OpenCV SimpleBlobDetector and http://www.learnopencv.com/blob-detection-using-opencv-python-c/ but still can't get any result with my simple image.

enter image description here

Here is my code in python

img = cv2.imread("map.jpg", cv2.IMREAD_GRAYSCALE)
params = cv2.SimpleBlobDetector_Params()
params.blobColor = 255
params.filterByColor = True
params.minArea = 16
params.filterByArea = True
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(255 - img)
len(keypoints)
# 0

OpenCV 3.1.0

Image is grayscaled.

UPD: Code updated following comment by @api55

17
  • you need to pass the blob params, setting the blobColor to 255 and filter by color to true. By default it tries to find dark blobs in white background. Or you could invert the colors of the image Commented May 11, 2016 at 12:33
  • @api55 I have updated code (in post too) but still no result Commented May 11, 2016 at 12:43
  • 1
    Try changing also the minArea parameter to something small, like 16 (4x4 pixel blob approx). In the tutorial, it says that filter by color is not working (not sure what version you have).... you can try inverting the image colors Commented May 11, 2016 at 12:51
  • @api55 Nothing changed Commented May 11, 2016 at 13:03
  • 1
    Please try the (updated) code here Commented May 11, 2016 at 13:41

2 Answers 2

1

I want to get some descriptors for each white area on image to filter that areas and operate with them separately. How can I do it?

My goal could be reached with sklearn.measure.label. This function returns a numpy array with the same shape and labels for each connected area.

But anyway it is still not clear why SimpleBlobDetector from OpenCV doesn't work.

Sign up to request clarification or add additional context in comments.

1 Comment

0

I was having the same problem. I had to remove the fiterbyarea parameter:

params.filterByArea = False

Comments

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.