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.

Labeling connections is explained in this article.

Solution (AVS)

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

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

  3. 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.
  4. Add filter ThresholdToRegion_Relative and connect to it the output of ReadVideo.

    The image below shows the region after the thresholding.

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

  6. 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). We can label that output SmallCoins. On the output outAbove we have regions of the bigger coins. Label it as BigCoins.

  7. Expand outputs outAccepted and outAbove and add 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 filter DrawStrings_SingleColor and draw outMessage on the input image.

  10. 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 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.
ThresholdToRegion_Relative Thresholds an image with a different threshold value for each pixel (inBaseImage(x, y) + inValue).
DelayByPeriod Suspends the program workflow for inTime milliseconds relative to the end of the filter's last invoke time.
SplitRegionIntoBlobs Segmentation of a region into individual objects when the objects do not touch each other.

Further Readings

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