Tracking two blobs of different colors

Hi all, I’m trying to track two blobs in the same grayscale frame at a time by calling find_blobs twice, one large dark blob with threshold set to [(0, 10)], and another small white blob with threshold set to [(200, 255)]. However, I realized when both blobs are in the same position, one of the blobs doesn’t get tracked anymore even though they’re 2 different colors, and there’s 2 seperate function calls for find_blobs with merge = False on both. How do I get them to detect blobs completely seperate of each other?

Hi, one function call should be enough without merge=True. Please check that area_threshold and pixel_threshold are set to not reject the blob. You can also pass multiple thresholds to find_blobs in a list.

Yep, I’ve been filtering based on blob area and position, drawing rectangles around the bounding box at each stage to see whats been detected and whats been filtered until I narrow it down to only what I want. If I’m only to use one find_blob call, how do I detect two ranges of grayscale color? I’d like to detect dark blobs between 0-10 and white blobs between 200-255 for example.

Hi,

Drawing on the image and then calling find_blobs() again will cause errors.

Just pass the thresholds to find_blobs() as [(0, 10), (200, 255)].

Oh I had no idea I could pass in 2 ranges like that. How do I tell which region does each blob belong to then? It’s important that each color is tied to a specific thing I’m tracking.
If I want to draw on the image, I must do it such that all the drawing is done after the blob tracking by storing the coordinates in a variable to draw later?

This is all explained in the documentation for find_blobs(). There’s a code() value returned by the blob which gives you it’s color index from the threshold list.

If I want to draw on the image, I must do it such that all the drawing is done after the blob tracking by storing the coordinates in a variable to draw later?

Yes, otherwise you are modifying the image.

That’s great, thanks! It’s important to keep merge = False while doing this right?

Yes, otherwise you’ll get two bits set in the code.

1 Like

In this project I did exactly the same.
But after finding the big black blob l look for the white blob inside the blob rect only…
Just an extra idea…

I see, that’s a great idea but won’t be necessary for my use case, thanks anyways!