You are here: Start » Program Examples » Coins

Coins

Aim:

Devise an algorithm that will count the amount of money visible in a video frame.

Input:

The single video file that contains coins on the white background. The video is stored in AVI format.

Output:

Amount of money visible in a single video frame.

Hints:

FabImage Studio offers a convenient way to perform offline inspection with images stored as single files or as a video file. To read a video file, the ReadVideo filter must be used. To store camera frames for further offline inspection, use the WriteVideo filter.

In many cases, the background of image is static and only objects under inspection are introduced to the inspection scene. To extract the background from an image, the SubtractImages filter may be used. But the most useful filter is the ThresholdToRegion_Relative, which selects regions of pixels by analyzing the intensity difference between them.

To avoid loading the background image in every iteration, the first video frame should be saved to an external FIDATA file. The image will be loaded only once, while the whole program is loaded from the file.

Obtaining coin values can be performed by analyzing their diameters. In the video, there are two kinds of coins. The first has a diameter around 40 pixels and the second has about 50 pixels. After coins extraction, the found region must be split into separate coins and then classified using one of the region features.

To compose a more complex string, the Formulas can be used.

Labeling connections is explained in this article.

Solution (FIS):

  1. Add the ReadVideo filter to the project and perform a single program iteration. Drop it in the ACQUIRE section.

  2. Add the DelayByPeriod filter to the same section. Set the inTime to 25 to slightly reduce the speed of the video.

  3. Save the first video frame to the FIDATA file..

    • Right click on the outImage output and use "Export to FIDATA file...",
    • Select a destination directory and a file name.
  4. Add the ThresholdToRegion_Relative and connect to it the output of the ReadVideo.

    The image below shows the region after the thresholding.

  5. Split the region into separate blobs using the SplitRegionIntoBlobs. Remove all regions that do not fit within the coin area.

  6. Add the ClassifyRegions and select the classifying feature as DiameterLength. Select the classifying range to (40, 50). Now, on the outAccepted output, we have all regions of smaller coins (1 eurocent). We can label that output SmallCoins. On the outAbove output, we have regions of the bigger coins. Label it as BigCoins.

  7. Expand the outAccepted and the outAbove and add the Count output. Label them SmallCount and BigCount.

  8. Add the Empty formula to the program and create:

    • Output outAmount of type Integer and compute the amount:

      Amount = SmallCount + BigCount * 5

    • Output outMessage of type String and create an output message:

      Message = toString(Amount) + " euro cent(s)"

  9. Add the DrawStrings_SingleColor and draw outMessage on the input image.

  10. Add the inImage to a new preview window.

Macrofilter Main extracts coins from video frames and calculates the visible money amount.

Used Filters

Icon Name Description
ClassifyRegions Use this filter when you have an array of regions and you want to select some of them for further processing.
DelayByPeriod Suspends the program workflow for inTime milliseconds relative to the end of the filter's last invoke time.
DrawStrings_SingleColor Draws strings (text) on an image with a single color.
ReadVideo Reads a frame sequence from a video file.
SplitRegionIntoBlobs Segmentation of a region into individual objects when the objects do not touch each other.
ThresholdToRegion_Relative Thresholds an image with a different threshold value for each pixel (inBaseImage(x, y) + inValue).

Further Readings

  • Blob Analysis - Article presents detailed information about the Blob Analysis technique.
  • Formulas - Detailed information about using formulas.