Part 2: Object detection and bread - The old world

Bubble count implementation with opencv

Posted by Gregor Tätzner


Count bubbles with opencv

As a follow up of last article Yolo Object Detection this time we try another approach without any training. The old library OpenCV (created in year 2000) provides plenty of modules for computer vision. For my simple bubble count I wanted to try the SimpleBlobDetector. Again you can find the code on this repo.

Arm the blobs

The detector is basically a simple python script that will configure and run the opencv blob detector.

Lets see the results for a well progressed dough:

python blob_detector.py --image data/testimg/bubbles.jpg
Matches: 215

Opencv blobs

The total count amounts to 215! Not bad for an slightly configured off the shelf algorithm.

Next run the same script with a fresh sample without bubbles:

python blob_detector.py --image data/testimg/no_bubbles.jpg
Matches: 10

Opencv no bubbles

It counts 10 bubbles this time. And most of them in the background. Probably with better images or smart cropping the results could be improved even more.

Another sample:

Opencv no bubbles 2

6 matches we have here. Again most of them in the background and 1 correct bubble on top inside the container.

Verdict

In summary this opencv blob detector actually outperforms the yolo model created previously and doesnt require any kind of training data or supervised learning. Admitted, the provided training data for yolo was really poor/small, but for simple use cases like this the more classic implementation of opencv seems to be superior.