You are here: Start » Tutorial Exercises » Conditions in Formulas

Conditions in Formulas

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 the conjunction directory.

Output:

Result of inspection highlighted on the input image.

Hints:

Use Edge-based Template Matching to find specific types of objects.

Use a Formula to analyze the results of Template Matching.

Labeling connections is explained in this article.

Solution (FIS):

  1. Add the EnumerateImages filter to the ACQUIRE section to obtain images from a directory.

  2. Add two LocateSingleObject_Edges1 filters and one LocateMultipleObjects_Edges1 filter (for bolts) to the 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:

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

  4. Add a new formula to the project and create three inputs: inMountMatch, inWasherMatch and inBoltsMatch from the consecutive outputs of the previous filters.

  5. Create the output outStatus with the formula:

    outStatus = inMountMatch <> Nil and (inWasher <> Nil or inBoltsMatch.Length == 2)

  6. Create the output outMessage with the formula:

    outMessage = outStatus ? "PASS" : "FAIL"

  7. Draw the message on 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.