# blob count

**URL:** <https://forums.openmv.io/t/blob-count/1813>\
**Category:** OpenMV Boards\
**Created:** [July 4, 2020, 10:45am UTC](https://forums.openmv.io/t/blob-count/1813 "2020-07-04T10:45:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [July 4, 2020, 10:45am UTC](https://forums.openmv.io/t/blob-count/1813/1 "2020-07-04T10:45:23Z")

</div>

Hi there!

new to openmv.

I’ve build a script for finding blobs in an image with img.find\_blobs().

is there any posibility to count the blobs on the image?

I’ve tried to use blob.count() but this isn’t what i want cause counts only merged blobs on a specific blob.

Is there a way?

---

<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:** [July 4, 2020, 2:29pm UTC](https://forums.openmv.io/t/blob-count/1813/2 "2020-07-04T14:29:59Z")

</div>

find\_blobs() Outputs a list. So just do len() on the list.

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [July 5, 2020, 6:16pm UTC](https://forums.openmv.io/t/blob-count/1813/3 "2020-07-05T18:16:06Z")

</div>

thanks a lot…

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [July 6, 2020, 1:46pm UTC](https://forums.openmv.io/t/blob-count/1813/4 "2020-07-06T13:46:42Z")

</div>

what i am trying to do is to inspect multiple areas in an image with multiple find blobs.  
What i need is to fire an output as soon as at least one blob is in specific area.

Till now every time a blob appears in an area i have an error.

I didn’t manage to get the len of findblobs.

```python
for blob in img.find_blobs([thresholds],invert=False,roi=(0,0,50,50),pixels_threshold=200, area_threshold=200, merge=True):
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
        
        blobs=len(find_blobs())
        if blobs>1:
                led.on()
        else:
                led.off()

```

---

<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:** [July 6, 2020, 2:18pm UTC](https://forums.openmv.io/t/blob-count/1813/5 "2020-07-06T14:18:23Z")

</div>

```python
blob_list = img.find_blobs([thresholds],invert=False,roi=(0,0,50,50),pixels_threshold=200, area_threshold=200, merge=True)
blob_count = len(blob_list)
if blob_count>1:
    led.on()
else:
    led.off()
for blob in blob_list:
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())

```

Hi, the OpenMV Cam runs Python code. Python rules apply. When you read the API you’ll notice the return type of methods. Given that return type… You can then Google how to use that return type in Python. Find\_Blobs() returns a list. Just because it was in the for loop doesn’t mean it wasn’t returning a list. It’s just that the list is implicitly consumed by the for loop.

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [July 9, 2020, 1:50pm UTC](https://forums.openmv.io/t/blob-count/1813/6 "2020-07-09T13:50:16Z")

</div>

dear friend,

i tested youe suggestion and it works like a charm!

maybe my question was too obvious for someone you has experience in python.  
i forgot to say that i am new to python too!

Your camera made me to deal with python…

thanks a lot!

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [July 9, 2020, 2:19pm UTC](https://forums.openmv.io/t/blob-count/1813/7 "2020-07-09T14:19:31Z")

</div>

i have made already an inspection that workings on 60 fps in WVGA2 and 50 pixels high with:

```python
sensor.set_windowing((752, 50))

```

this works great on 60 frames per second!

```python
    img = sensor.snapshot() # Take a picture and return the image.
    

    blob_list1 = img.find_blobs([thresholds],invert=False,roi=(0,0,50,50),pixels_threshold=200, area_threshold=200, merge=True)
    blob_count1 = len(blob_list1)
    if blob_count1>0:
        led.on()
    else:
        led.off()
        
    for blob in blob_list1:
            img.draw_rectangle(blob.rect())
            img.draw_cross(blob.cx(), blob.cy())

```

when i am trying to use a second blob for a second area the fps dicrease to 30 fps.  
But if i use more find blobs the fps remains the same 30fps.

This is the code for all 4 find blobs:

```python
    img = sensor.snapshot() # Take a picture and return the image.
    

    blob_list1 = img.find_blobs([thresholds],invert=False,roi=(0,0,50,50),pixels_threshold=200, area_threshold=200, merge=True)
    blob_count1 = len(blob_list1)
    if blob_count1>0:
        led.on()
    else:
        led.off()
        
    for blob in blob_list1:
            img.draw_rectangle(blob.rect())
            img.draw_cross(blob.cx(), blob.cy())
            

    blob_list2 = img.find_blobs([thresholds],invert=False,roi=(100,0,50,50),pixels_threshold=200, area_threshold=200, merge=True)
    blob_count2 = len(blob_list2)
    if blob_count2>0:
        led1.on()
    else:
        led1.off()
        
    for blob in blob_list2:
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())

    blob_list3 = img.find_blobs([thresholds],invert=False,roi=(200,0,50,50),pixels_threshold=200, area_threshold=200, merge=True)
    blob_count3 = len(blob_list3)
    if blob_count3>0:
        led2.on()
    else:
        led2.off()
        
    for blob in blob_list3:
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
        

    blob_list4 = img.find_blobs([thresholds],invert=False,roi=(300,0,50,50),pixels_threshold=200, area_threshold=200, merge=True)
    blob_count4 = len(blob_list4)
    if blob_count4>0:
        led.on()
    else:
        led.off()
        
    for blob in blob_list4:
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())

```

what is your opinion? is this ok?  
why the inspection time is the same with 2,3,4 find blobs and with only one find blob is too much faster?  
DO i miss something again?

---

<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:** [July 9, 2020, 5:36pm UTC](https://forums.openmv.io/t/blob-count/1813/8 "2020-07-09T17:36:48Z")

</div>

It’s because once you take to long and miss the next frame. So, then you halve the speed.

It’s like a 1/N thing. When you take less time you are exponentially faster. Once you take too long you loose large chunks of speed.

1/2, then 1/3, then 1/4, etc.

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [July 10, 2020, 7:09am UTC](https://forums.openmv.io/t/blob-count/1813/9 "2020-07-10T07:09:04Z")

</div>

Thanks again,

Noproblem at all

30 fps is good for me…
