Egg Detection

I am trying to use OpenMV to detect and eventually count eggs on a conveyor.
I’ve been tinkering with find_blobs() and have had good success finding them when lighting conditions are consistent with the threshold (they usually aren’t).
The biggest problem I am having is when two eggs are close to each other, it counts them as the same blob (because of the threshold I’m guessing).
Any tips anybody can give me on better ways to detect and distinguish oval(ish) objects?


My code is something like this:

thresh = [(7, 100, -128, 127, -128, 127)]

def find_blobs(img):
    blobs = img.find_blobs(thresh)
    for b in blobs:
        if b.area() >= 3000 and b.area() <= 6000: # filter blob sizes
            
            # debug blob sizes
            img.draw_string(b.x(), b.y() -15, str(b.area()),color=(0, 255, 0), scale=1.5)
            img.draw_rectangle(b.rect(), color=(0, 255, 0))

The best thing to do would be to look to see if the blob is elongated and then just count it as two in that case. We have a method that returns an elongation score. Just use that and threshold the score to decide between counting a blob as 1 or 2.

Thanks! I’ll try that, I also considered using haar cascade or training a neural network but I think those might be slower (not that speed is necessary in this case).