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 Aurora Vision Studio, please refer to that example. If you are new to Aurora Vision Studio, then carry on here.

The first step to perform required inspection is the 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.

Labeling connections is explained in this article.

Solution (AVS)

  1. In Workspace Explorer open workspace Examples and in Film strip window select CapEasy dataset. Drag the Image channel to the ACQUIRE section.

  2. Add the ScanSingleEdge filter. Connect the outImage output of the ReadFilmstrip to the inImage.

  3. Click on the ScanSingleEdge filter. In the Properties window in the left bottom corner, choose the 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 the outEdge.Point to the inPoint. It will create a local coordinate system at the point where the edge has been found.

  5. Add another ScanSingleEdge filter. Connect the outImage output of the ReadFilmstrip to the inImage, and connect the outCoordinateSystem to the inScanPathAlignment.

  6. Now go to the Project Explorer (the left side of Aurora Vision Studio). Create a new global parameter. Name it ScanSegments which will be of the Segment2DArray type. Then define three scanning paths as shown in the image below: Connect the ScanSegments to the 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. Use Show/Hide ports option to add the outEdge.IsNil output. Label it as DefectPresent.

  9. Add a new formula. Use label DefectPresent in the statement without connecting it to the filter:

    outIsOK = all(DefectPresent) ?? False

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

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

  12. Connect the macrofilter's input inIsOK to the inCondition.

  13. Add the DrawStrings_MultiColor filter:

  14. Add the CreateBox filter:

  15. 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.
CreateCoordinateSystemFromPoint Most often used to define an object alignment from results of 1D Edge Detection or Blob Analysis.
ScanSingleEdge Very fast detection of an object (e.g. horizontal displacement of a bottle) and simple measurements (e.g. liquid level in a bottle).
CreateBox Creates a box.
DrawRectangles_SingleColor Draws rectangles on an image with a single color.
DrawStrings_MultiColor Draws strings (text) on an image with multiple colors.

Further Readings