You are here: Start » Tutorial Exercises » Conditions in Formulas (conjunction)
Conditions in Formulas (conjunction)
Aim
Create an algorithm that checks if the input image contains a certain set of objects.
Inspection should pass in three cases:
- There is a mount and two bolts in the image or
- there is a mount and a single washer or
- there is a mount and a single washer and two bolts.
Input
The set of images with different objects.

Images are stored in
conjunctiondirectory.
Output
Result of inspection drawn on the input image.

Hints
Use Edge-based Template Matching to find particular types of objects.
Use formulas to analyze the results of Template Matching.
Solution (AVS)
-
Add two LocateSingleObject_Edges filters and one LocateMultipleObjects_Edges filter (for bolts) and create models as shown in the images below:
-
Model of a washer:

-
Model of a mount:

-
Model of a bolt:

-
In all these filters set inMinScore to 0,9. Also set inMinPyramidLevel to 2. In the filter responsible for finding bolts, set inMinDistance to 50.
-
-
Add a new formula to the project and create three inputs: inMountMatch, inWasherMatch and inBoltsMatch from consecutive outputs of the previous filters.
-
Create an output outStatus with formula:
outStatus = inMountMatch <> Nil and (inWasher <> Nil or inBoltsMatch.Length == 2)
-
Create an output outMessage with formula:
outMessage = outStatus ? "PASS" : "FAIL"
-
Draw the message on the input image using DrawStrings_TwoColors filter.

Additional Tasks
-
Create the equivalent of the formula using blocks.
-
Make the condition more strict to pass only if two bolts are present and a washer is not present. Or, if a washer is present and no bolts are present. Tip: it is enough to change a single operator to provide this functionality.
