You are here: Start » Tutorial Exercises » Bottle Inspector Part 1: Counting Bottles (bottles_1_counting)

Bottle Inspector Part 1: Counting Bottles (bottles_1_counting)

Aim

Prepare a program that returns the number of bottles found in the provided images.

Input

A set of images with bottles. The bottle count may vary but the maximal number of bottles is 4.

Images are stored in bottles directory.

Output

An image with the bottle count printed on it.

Hints

The bottle tops can be viewed as darker regions on the brighter background. The profile below shows the transitions of brightness values along a selected scan path. We want to detect the objects that start with a bright-to-dark transition and end with an opposite one.

The ScanMultipleStripes filter can be used for this purpose.

Solution (AVS)

  1. Add EnumerateImages filter to load images from files.

  2. Add ScanMultipleStripes filter.

  3. Open the path editor for the parameter inScanPath and set the path as in the picture below:

  4. In ScanMultipleStripes filter set the following parameters:

  5. Expand outStripes output of ScanMultipleStripes filter. Choose Count property output.

  6. Add a new formula. Connect outStripes.Count to it as inBottleCount. Add another input - inExpectedCount set to 4. Create an output outCountOK:

    outCountOK = inBottleCount == inExpectedCount

  7. Add DrawStrings_TwoColors filter to draw the number of bottles. Set inLocations parameter to any suitable location within the input image. Connect outStripes.Count to inStrings and outCountOK to inConditions.

Macrofilter Main

Further Readings