blob count

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?

find_blobs() Outputs a list. So just do len() on the list.

thanks a lot…

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.

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()
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.

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!

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

sensor.set_windowing((752, 50))

this works great on 60 frames per second!

    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:

    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?

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.

Thanks again,

Noproblem at all

30 fps is good for me…