# 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](/function-blocks/input-output/image-inputs/load-image.md) block in an empty scenario with the example image shown below:

<figure><img src="/files/D01YdjY0d3i7sxRTIGSj" alt=""><figcaption></figcaption></figure>

As a first step, we'll need to separate the coins from the background using the [Image Threshold](/function-blocks/image-transformations/color-filters/image-threshold.md) block. This can also be done with [HSV Filter](/function-blocks/image-transformations/color-filters/hsv-filter.md) or [RGB Mask](/function-blocks/image-transformations/color-filters/rgb-mask.md) but separating the color areas and acquiring a binary image will suffice. Create the logic below:

<figure><img src="/files/vcZPBHVIdB0BkGbX4ib9" alt=""><figcaption></figcaption></figure>

Since we'll be using the [Find Contour](/function-blocks/detections-shapes/shape-analysis/find-contour.md) 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:

<figure><img src="/files/n2273E3EvTczwCwjy15c" alt=""><figcaption></figcaption></figure>

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](/function-blocks/image-transformations/transformation-filters/distance-transformation.md) block:

<figure><img src="/files/pm7Os1HJ87EZjtFQNRM0" alt=""><figcaption></figcaption></figure>

Distance transformation calculates how far away each pixel from white color density. Using [Image Threshold](/function-blocks/image-transformations/color-filters/image-threshold.md) again will yield distinct white areas for each one:

<figure><img src="/files/WcgGQxRliL5Mfo3jR1KK" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/FywCj6nstu6sF5S7UnOB" alt=""><figcaption></figcaption></figure>

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/example-projects/object-counting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
