You are here: Start » Program Examples » Button Presence

Button Presence

Aim

The purpose of this example is to check whether all buttons are correctly placed on a board.

Input

An image of a board which can appear at different positions and angles.

Output

Detected missing buttons:

Hints

Due to the variable board position the region of interest must be aligned. In this case it is highly recommended to verify the buttons presence by analysing pixel intensities in the specified region. You can create a grid of circles corresponding to each button. In other words this grid should be an array of regions of interest.

Labeling connections is explained in this article.

You can learn how to turn on sections here.

Solution (AVS)

  1. Enable sections clicking on the Show Sections () button.

  2. Add EnumerateImages filter to the ACQUIRE section to load consecutive images from the specified directory. Label the outImage as Image and outFileName as FileName.

  3. To find the position and orientation of the board add ThresholdToRegion filter to the PROCESS section and set its input inMax to 115. Since the PROCESS section should consist of key functionalities of the application, most of the tools will be placed here.

  4. Create a rectangle containing the output region of ThresholdToRegion by adding RegionBoundingRectangle filter. The board is rectangular, thus the output rectangle outBoundingRectangle represents its boundaries.

  5. Now a coordinate system can be created by using CreateCoordinateSystemFromRectangle. This is very common way to obtain an alignment, since Rectangle2D data type contains information about a position of the top-left corner and rotation of the rectangle.

  6. Once the alignment is created, it is time to create an array of ROIs. Add CreatePointGrid filter to the INITIALIZE section and set its following properties:

  7. To obtain a 2D array of circles, instead of the array of points, add CreateCircle filter to the INITIALIZE section and connect its input inPoint to the outPointGrid. Set inRadius to 10. Please note that creating the grid of circles is not necessary in every cycle of the program. It can be done only once, during the first iteration. Therefore filters responsible for setting values of constant parameters should be placed in INITIALIZE section.

  8. Inspection of the buttons presence can be performed by CheckPresence_Intensity filter. Add this filter to PROCESS section and connect its inputs:

  9. By dragging and dropping the output outAlignedRoi to the preview, you can see the created grid with circles corresponding to each button.

  10. Put the outContrast value on preview window and iterate once the program. Note that if button is present, the contrast value is about 50. Otherwise it is about 10. Therefore set inMinContrast to 20. outIsPresent is an array of inspection results. Label that output as IsPresent.

  11. To summarize the performed inspection add Empty formula filter and create two outputs. Note, that labeled outputs does not have to be connected to the formula to be used inside of it.

    • In this expression we concatenate 3 strings together using the + sign. First we join the inFileName with missing:. Then we need information about number of missing objects. To get that, we use count function. The not before inIsPresent denote that we are looking for the False occurrences. Finally we convert the extracted number into string using toString function.

    InspectionResult = FileName + " missing: " + toString(count(not IsPresent))

    • In this expression we use a contractor of StringLabel type. As the first argument a text should be provided. In this case it is labeled output InspectionResult. As second argument a Point2D is needed. So we use a Point2D constructor and specify the X and Y coordinates directly.

    Label = StringLabel(InspectionResult, Point2D(10, 10))

  12. Accumulate messages from all the iterations by adding AccumulateElements and connecting its inElement input with Formula's InspectionResult output.

  13. Add SaveTextLines filter to the FINALIZE section to save all the messages that include the inspection results.

Main

Used Filters

Icon Name Description
SaveTextLines Saves text lines to a file.
EnumerateImages Emulates image acquisition with images stored on disk.
CreateCoordinateSystemFromRectangle Most often used to define an object alignment from a filter like RegionBoundingRectangle.
CreatePointGrid Creates a grid of points.
RegionBoundingRectangle_OrNil Computes the smallest rectangle containing a region; returns NIL if the region is empty.
ThresholdToRegion Extraction of a region of objects that can be defined by a salient brightness.
CheckPresence_Intensity Quick and easy presence verification, e.g. for missing caps, screws, labels.
CreateCircle Creates a circle from an aligned point and radius.
AccumulateElements Creates an array from elements appearing in many iterations.

Further Readings