# about find\_blob function

**URL:** <https://forums.openmv.io/t/about-find-blob-function/900>\
**Category:** OpenMV Boards\
**Created:** [September 19, 2018, 6:55pm UTC](https://forums.openmv.io/t/about-find-blob-function/900 "2018-09-19T18:55:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![suik52](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@suik52](https://forums.openmv.io/u/suik52)\
**Post date:** [September 19, 2018, 6:55pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/1 "2018-09-19T18:55:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [September 20, 2018, 4:03pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/2 "2018-09-20T16:03:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![suik52](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@suik52](https://forums.openmv.io/u/suik52)\
**Post date:** [September 27, 2018, 4:08pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/3 "2018-09-27T16:08:21Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [September 27, 2018, 4:43pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/4 "2018-09-27T16:43:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![suik52](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@suik52](https://forums.openmv.io/u/suik52)\
**Post date:** [September 27, 2018, 5:13pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/5 "2018-09-27T17:13:17Z")

</div>

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？

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [September 27, 2018, 5:17pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/6 "2018-09-27T17:17:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![suik52](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@suik52](https://forums.openmv.io/u/suik52)\
**Post date:** [September 28, 2018, 12:30am UTC](https://forums.openmv.io/t/about-find-blob-function/900/7 "2018-09-28T00:30:04Z")

</div>

thank you very much. i will dive into the source code of find\_blob 🙂

---

<div class="post-metadata">

**Author:** ![suik52](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@suik52](https://forums.openmv.io/u/suik52)\
**Post date:** [September 28, 2018, 2:18am UTC](https://forums.openmv.io/t/about-find-blob-function/900/8 "2018-09-28T02:18:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [September 28, 2018, 4:29pm UTC](https://forums.openmv.io/t/about-find-blob-function/900/9 "2018-09-28T16:29:29Z")

</div>

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