You are here: Start » Program Examples » Coins



Devise an algorithm which will count the money amount visible on a video frame.


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


Amount of money visible on a single video frame.


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

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

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

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

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

Labeling connections is explained in this article.

Solution (FIS)

  1. Add the ReadVideo filter to project and perform 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 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 not fits the coin area.

  6. Add the ClassifyRegions and select classifying feature to DiameterLength. Select 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 program and create:

    • Output outAmount of type Integer and compute amount:

      Amount = SmallCount + BigCount * 5

    • Output outMessage of type String and create there 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 visible money amount.

Used Filters

Icon Name Description
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.
ClassifyRegions Use this filter when you have an array of regions and you want to select some of them for further processing.
ThresholdToRegion_Relative Thresholds an image with a different threshold value for each pixel (inBaseImage(x, y) + inValue).
DrawStrings_SingleColor Draws strings (text) on an image with a single color.
DelayByPeriod Suspends the program workflow for inTime milliseconds relative to the end of the filter's last invoke time.

Further Readings

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