You are here: Start » Program Examples » Cap (Easy)

Cap (Easy)

Aim

The task of this example is to check whether a seal (plastic ring under the cap) is correctly placed.

Input

An image of the top of a bottle. The position of the bottle is variable.

Output

The result of the inspection printed on the image. If a defect is detected, a rectangle is drawn around it.

Hints

This is an easier variant of the same example "Caps". If you are on a more advanced level in programming in Adaptive Vision Studio, please refer to that example. If you are new to Adaptive Vision Studio, then carry on here.

The first step to perform required inspection is detection of the position of an object in an image. As the bottle moves particularly along the X axis and the background is consistent, the best way would be applying the 1D Edge Detection technique and creating a local coordinate system based on a detected edge.

Solution (AVS)

  1. Add the EnumerateImages filter and define the inDirectory input (where your images are stored).

  2. Add the ScanSingleEdge filter. Connect outImage to inImage.

  3. Click on the ScanSingleEdge filter. In the Properties window in the left bottom corner, choose inScanPath and define the scanning path, so that it could find the left edge of the cap. Set the inEdgeScanParams.MinMagnitude to 10 to inure edges to possible noise.

  4. Add the CreateCoordinateSystemFromPoint filter. Connect outEdge.Point to inPoint. It will create a local coordinate system at the point where the edge has been found.

  5. Add another ScanSingleEdge filter. Connect outImage to inImage, and connect outCoordinateSystem to inScanPathAlignment.

  6. Now go to the Project Explorer (the left side of Adaptive Vision Studio). Create a new global parameter. Name it ScanSegments which will be of Segment2DArray type. Then define three scanning paths as shown in the image below: Connect ScanSegments to inScanPath. This filter will be now executed in an array mode.

  7. Click on the ScanSingleEdge filter and in the Properties window make following changes:

  8. Add a new formula. Connect outEdge.IsNil to it as a whole array (choose BoolArray type instead of single Bool in the window that appears while connecting an output to a formula) and name it inIsNil. Input the following statement:

    outIsOK = all(inIsNil) ?? False

  9. Now create a new step macrofilter, name it DrawResults and connect following inputs to it:

    • outImage as inImage,
    • outEdge.Point (from the latter filter) as inDefectLocations,
    • Formula's outIsOK output as inIsOK.
  10. Step inside the newly-created macrofilter. Add ChooseByPredicate of String type. In the Properties window set following values:

  11. Connect macrofilter's input inIsOK to inCondition.

  12. Add the DrawStrings_TwoColors filter:

  13. Add the CreateBox filter:

  14. Add the DrawRectangles_SingleColor filter:

Macrofilter Main

Macrofilter DrawResults

Used Filters

Icon Name Description
ChooseByPredicate E.g. to choose GREEN color to visualize correct objects or RED to visualize defective ones.
EnumerateImages Emulates image acquisition with images stored on disk.
CreateBox Creates a box.
DrawStrings_TwoColors Draws strings (text) on an image with two colors, depending on the status of each string (usually: green or red for pass/fail status).
ScanSingleEdge Very fast detection of an object (e.g. horizontal displacement of a bottle) and simple measurements (e.g. liquid level in a bottle).
CreateCoordinateSystemFromPoint Most often used to define an object alignment from results of 1D Edge Detection or Blob Analysis.
DrawRectangles_SingleColor Draws rectangles on an image with a single color.

Further Readings