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 the other words this grid is an array of regions of interest.
Solution (AVS)
-
Add EnumerateImages filter to get load consecutive images of some disk directory.
-
To find the position and orientation of the board add ThresholdToRegion filter and set its input inMax to 115.
-
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.
-
Before creating a coordinate system from the rectangle, normalization of its orientation is required. This can be achieved by adding NormalizeRectangleOrientation filter.
-
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.
-
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.
-
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:
-
The alignment is created, therefore it is time to create an array of ROIs. Add CreatePointGrid filter and set its following properties:
- inPoint.X to 21 and inPoint.Y to 16,
- inRowCount to 6 and inColumnCount to 10,
- both inRowStep and inColumnStep to 23, since this is the distance between the centers of neighboring buttons.
-
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.
-
Inspection of the buttons presence can be performed by CheckPresence_Intensity filter. Add this filter and connect its inputs:
- inImage to the output of filter EnumerateImages,
- inRoi to the output of CreateCircle,
- inRoiAlignment to the output of FindBoard macrofilter.
-
By dragging and dropping the output outAlignedRoi to the preview, you can see the created grid with circles corresponding to each button.
-
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.
-
To draw the results on an output image, add DrawCircles_TwoColors filter and connect its inputs:
- inImage to the output of filter EnumerateImages,
- inCircles to the output of CreateCircle,
- inCircleAlignment to the output of FindBoard macrofilter.
- inConditions to outIsPresent.
-
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.
-
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.
-
In Properties window set inString1 to Missing:.
-
Add DrawStrings_SingleColor filter to draw the created string value on the image. Set the inLocation and inColor in the Properties window.
-
Now a macrofilter responsible for drawing the results can be created. Select the filters added in steps 14-18 and create the Step macrofilter DrawResults in the same way as FindBoard.
-
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)....
-
The final result is the output image of DrawResults macrofilter.
Macrofilter Main
Macrofilter FindBoard
Macrofilter DrawResults
Macrofilter MainLoop
Used Filters
Icon | Name | Description |
---|---|---|
![]() |
DrawStrings_SingleColor | Draws strings (text) on an image with a single color. |
![]() |
NormalizeRectangleOrientation | Changes orientation of the given rectangle according to parameters. |
![]() |
CreateCoordinateSystemFromRectangle | Most often used to define an object alignment from a filter like RegionBoundingRectangle. |
![]() |
CreatePointGrid | Creates a grid of points. |
![]() |
DrawCircles_TwoColors | Draws circles on an image with two colors, depending on the status of each circle (usually: green or red for pass/fail status). |
![]() |
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. |
![]() |
EnumerateImages | Emulates image acquisition with images stored on disk. |
![]() |
CreateCircle | Creates a circle from an aligned point and radius. |
![]() |
ThresholdToRegion | Extraction of a region of objects that can be defined by a salient brightness. |
![]() |
RegionBoundingRectangle | Computes the smallest rectangle containing a region. |
![]() |
ConcatenateStrings | Joins two or more strings into a single one. |