Object Counting

Counting objects is a widely encountered problem in the computer vision field. This tutorial will teach you how to count circular objects in a given area using conventional computer vision algorithms.

The example image is already provided in AugeLab Studio in the example images folder as coins2.jpg file.

Create Load Image block in an empty scenario with the example image shown below:

As a first step, we'll need to separate the coins from the background using the Image Threshold block. This can also be done with HSV Filter or RGB Mask but separating the color areas and acquiring a binary image will suffice. Create the logic below:

Since we'll be using the Find Contour block to count how many distinct white area exist, we'll be selecting THRESH_BINARY_INV option to filter the image and adjust the slider to filter the background.

However, you may see that white areas are not separated from each other perfectly. Using the Find Contour block would yield the wrong result:

As you see, there aren't 14 block coins in the provided image. We'll need an algorithm to separate or shrink the white areas. For this, we'll be using the Distance Transformation block:

Distance transformation calculates how far away each pixel from white color density. Using Image Threshold again will yield distinct white areas for each one:

Now, using the find contour block should yield how many coins we have the in reference image:

That's it! You now know how to count each object in a given area with AugeLab Studio!

Last updated