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 Formula to analyze the results of Template Matching.
Labeling connections is explained in this article.
Solution (AVS)
-
Add EnumerateImages filter to ACQUIRE section to obtain images from a directory.
-
Add two LocateSingleObject_Edges1 filters and one LocateMultipleObjects_Edges1 filter (for bolts) to PROCESS section and create models as shown in the images below:
-
The model of a washer:

-
The model of a mount:

-
The 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 the output outStatus with formula:
outStatus = inMountMatch <> Nil and (inWasher <> Nil or inBoltsMatch.Length == 2)
-
Create the output outMessage with formula:
outMessage = outStatus ? "PASS" : "FAIL"
-
Draw the message in the input image using DrawStrings_MultiColor filter. Connect outImage with inImage, outStatus and outMessage from the previous filter with inColorIds and inStrings respectively.

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.
Further Readings
- Formulas - Detailed information about using formulas.
- Template Matching - Most detailed description of the Template Matching technique.
