You are here: Start » Program Examples » Coins

Coins

Aim

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

Input

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

Output

Amount of money visible on a single video frame.

Hints

Adaptive Vision 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 filter ReadVideo must be used. To store camera frames for further off-line inspection use WriteVideo files.

In many cases background of images are still and only objects under inspection are introduced to the inspection scene. To extract background from image filter SubtractImages may be used. But the most useful filter is ThresholdToRegion_Relative which select 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 AVDATA 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 found region must be split into separate coins and then classified using one of region feature.

To compose more complex string Formulas can be used.

Solution (AVS)

  1. Add filter ReadVideo to project and perform single program iteration,

  2. Save the first video frame to the AVDATA file..

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

    The image below shows the region after the thresholding.

  4. Split region into separate regions using filter SplitRegionIntoBlobs. Remove all regions that not fits the coin area.

  5. Add filter 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) and on the output outAbove we have regions of the bigger coins.

  6. Expand outputs outAccepted and outAbove and add Count output.

  7. Add the Empty formula to program and create:

    • Input inOneCentCount of type Integer. Connect to it outAccepted.Count.
    • Input inFiveCentCount of type Integer. Connect to it outAbove.Count.
    • Output outAmount of type Integer and compute amount.

      outAmount = inOneCentCount + inFiveCentCount * 5

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

      outMessage = toString(outAmount) + " euro cent(s)".

  8. Add filter DrawStrings_SingleColor and draw outMessage on the input image.

  9. Add inImage to a new preview window.

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

Used Filters

Icon Name Description
ClassifyRegions Use this filter when to you have an array of regions and you want to select some of them for further processing.
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.