You are here: Start » Program Examples » Button Presence

Button Presence

Aim

The task 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 varying positions and angles.

Output

Detected missing buttons:

Hints

As the board position is variable, 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 is an array of regions of interest.

Solution (AVS)

  1. Add EnumerateImages filter to get load consecutive images of some disk directory.

  2. To find the position and orientation of the board add ThresholdToRegion filter and set its input inMax to 115.

  3. 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.

  4. Before creating a coordinate system from the rectangle, normalization of its orientation is required. This can be achieved by adding NormalizeRectangleOrientation filter.

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

  6. Now a macrofilter responsible for finding the board in the image can be created. This can be done by selecting all filters added in the previous steps, right clicking on one of them and choosing the Extract Step... command from the context menu. Following the verb + noun naming convention, where the name of macrofilter describes its purpose, call it FindBoard.

  7. Enter into the created macrofilter and add output outAlignment of type CoordinateSystem2D. This can be performed by dragging and dropping the outCoordinateSystem connection over Macrofilter Outputs area, like in the image below:

  8. The alignment is created, therefore it is time to create an array of ROIs. Add CreatePointGrid filter and set its following properties:

  9. To obtain a 2D array of circles, instead of the array of points, add CreateCircle filter and connect its input inPoint to the outPointGrid. Set inRadius to 10.

  10. Inspection of the buttons presence can be performed by CheckPresence_Intensity filter. Add this filter and connect its inputs:

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

  12. 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.

  13. outIsPresent is an array of inspection results.

  14. To calculate a number of missing buttons add CountValueInArray filter and set its property inValue to false. This filter counts the false values in the array.

  15. To create a string which will be drawn on the image, add ConcatenateStrings filter and connect its input inString2 to outCount. Note that this is example of automatic conversion from the Integer type to the String.

  16. In Properties window set inString1 to Missing:.

  17. Add MakeStringLabel filter to create a label with information about missing buttons. This filter combines a inPosition with inText creating new type convention for string displaying, called outLabel.

  18. Actually, that would be the end of this example. However, please note that creating the grid of circles is unnecessary in every loop of the program. It can be created once, during the initial iteration. Therefore you need to create a Task macrofilter and name it MainLoop. Before that, move the filters CreatePointGrid and CreateCircle to the top of Program Editor. Now the Task macrofilter can be created in the same way as the Step macrofilters. Just select all filters in the Program Editor, except the CreatePointGrid and CreateCircle, right-click on one of them and choose Extract Task (loop)....

  19. The final result is the output image of DrawResults macrofilter.

Macrofilter Main

Macrofilter FindBoard

Macrofilter MainLoop

Used Filters

Icon Name Description
EnumerateImages Emulates image acquisition with images stored on disk.
MakeStringLabel Creates a StringLabel structure from individual fields.
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.
CountValueInArray Calculates the number of occurrences of an object in an array.
CheckPresence_Intensity Quick and easy presence verification, e.g. for missing caps, screws, labels.
NormalizeRectangleOrientation Changes orientation of the given rectangle according to parameters.
CreateCircle Creates a circle from an aligned point and radius.
ConcatenateStrings Joins two or more strings into a single one.

Further Readings