about find_blob function

Hi guys. i tried the auto color tracking one from the color tracking example, and i found it can output the result i want. currently i am using opencv python, and already built up function to auto calibrate the target object color which means i got the threshold value. but the problem is i have hard time to write main part algorithm to filter out the object say red ball, so i am thinking maybe i could use the algorithm in find_blob. I tried read the c code in github but it’s really long and i completely lost. im wondering if someone can briefly explain the algorithm behind the find_blob function like what type of filter it used and any pre process method? thanks for any help.

Hi, the find blob method is just a wild fire scanline flood fill algorithm. The way it works is to walk every pixel in the image, find a pixel which matches the color bounds, the “burn” all the pixels connected to that pixel by doing a breath/depth first search and setting visited nodes in a bitmap. Then go back to scanning the image for matching colors while skipping past pixels that were already set int he bitmap.

Afterwards, the algorithm then joins blobs and detentions and whatnot to get a clear output.

If you are using opencv there’s this method called find_contours that kinda does what you want.

Hi, sorry for the late reply and thanks for your explaination. Because right now i am doing the same thing which is automatic calibration and color tracking in opencv using mac front cam , and i found there is no way to turn off the auto whitening and auto gain for mac front cam. so i am wondering that if i applied exactly the alogrithm using in find_blob ,would i get similar result without turn off auto whitening and auto gain? In other word, are auto whitening and auto gain that crucial in color tracking. i found the automatic color tracking example outputs way better result than what i did in opencv for auto calibration color tracking, so i just want to make sure whether this algorithm still works well even without turning off auto gain and whitening. thanks .

Um, you have to turn off auto gain and auto white balance. Note that you can capture the camera settings and force the values to be whatever too based on previously determined values.

In general, auto gain and auto white balance HEAVILY change color values making simple color tracking impossible. If you can’t turn them off then you can’t use the camera on the PC and you need another camera where you have more control.

hi, I dont think there is a way in opencv or in my system setting to turn off the auto gain and auto whiteningsetting for mac cam. one thing I noticed while i was playing around the openmv is that even if I turned on auto gain and auto whitening, i still can track the object using the auto color tracking example as long as i am not putting the light source directly on the cam screen and it works kind of well , it’s not like i turn these on and next time i run the same script it can not track the object at all. so i am just not sure if these two auto things can completely ruin the script algorithm or under some stable lightning condition like without direct light source it could be fine?

So, autogain and auto white balance react to the colors in the scene. As long as the object you are tracking doesn’t get too close to the camera and that the lighting doesn’t change you should be fine.

thank you very much. i will dive into the source code of find_blob :slight_smile:

sorry,I just came up another question. because you mentioned that in the floodfill algorithm, you analyze each pixel bound and its neigbor, I heard and also tried that its really slow to access each pixels, i am wondering would this algorithm be very slow or is there something i misunderstood

Our code is in C. You can’t do anything fast at the python level. You have to edit the C firmware.