You are here: Start » Tutorial Exercises » Detecting of the Screw and the Washer (screw_and_washer)

Detecting of the Screw and the Washer (screw_and_washer)

Aim

Prepare an algorithm that finds a screw and a washer in the provided images.

Input

A set of images with a single screw mounting point. To mark the test as passed, both the screw and the washer must be located be in the image.

Images are stored in screw_and_washer directory.

Output

The input image with marked screw and washer on it. Also, a string Pass/Fail should be displayed on the image.

Hints

To mark the object under inspection as valid, both the washer and the screw must be found.

Both the screw head and the washer have a circular shape. To locate them in the image the DetectSingleCircle filter can be used.

The conditional value on the output of the DetectSingleCircle makes it possible to make the finding of the second circle depend on the result of the previous operation. Find out which object should be found first.

Use a formula to prepare a message that should be displayed on the image depending on the results of locating the elements.

Solution (AVS)

  1. Add EnumerateImages filter to obtain images from the input directory.

  2. Use a measuring tool to find the diameters of the washer and the screw's head.

  3. Add two DetectSingleCircle filters to the project. In the first filter set inRadius to the value of found radius of the washer. It is about 57,0px. Set also the minimal score of the result to 42. The circle found by the first filter should narrow the inRoi of the next filter. Connect the outCircle.Circle of the first filter to inRoi of the second filter. In this case, the washer is larger than the screw and we can assume that the screw lays in the washer's circle. In other case, the detecting of screw and the washer should be done separately. To assure that only washer circle will be found set washer's minimal score to 65,0. Also, finding the screw can be done with a higher minimal score set to 32.

  4. To check if the objects were found the formula can be used. It is enough to only check if the circle was found by the second filter. To do that, the comparison operator should be used with ?: operator. Using this operator create the inspection result message.

  5. To draw string in color, the input image should be converted to RGB. To do that, use ConvertToMultichannel filter.

  6. Finally, the message can be drawn on the image using the DrawStrings_TwoColors filter.

  7. Show the created image in the preview window.

Macrofilter Main finds two elements using Detecting Circle technique.