You are here: Start » Program Examples » Bottle Inspection

Bottle Inspection

Aim

The task of this example is to check the number of bottles, their orientation, level of a liquid and presence of a foam.

Input

An image of bottles. The position of the bottles may change both in relation to the camera as well as other bottles.

Output

An image with the result of the inspections drawn on it. If a defect is detected, a rectangle is drawn around it.

Hints

The location of the object is variable. Some of the steps for this program have been described in the following tutorials:

Bottle Inspector Part 1: Counting Bottles

Bottle Inspector Part 2: Measuring Liquid Level

Bottle Inspector Part 3: Foam Detection

Orientation of the bottle can be determined by finding an asymmetrical part of the bottle, like the top of it.

Solution (AVS)

  1. In Workspace Explorer open workspace Examples and in Film strip window select BottleInspection dataset. Drag the Image channel to the ACQUIRE section.

  2. Follow the steps described in the tutorials mentioned in the hints section.

  3. When the program resembles the one from the end of the third tutorial add the AlignRectangle filter.

    • Connect the outBottleAlignments output form the CreateCoordinateSystemFromPoint to the inAlignment input.
    • Iterate the program once. Enter the editor (click "..." next to the inRectangle) and draw a rectangle of roughly the size of the cap of a bottle.
    • Drag the outAlignedRectangle to one of the inData ports of view2DBox_PassFail indicator in the HMI.
    • Make sure the Coordinate System field is set to inAlignment and then move the rectangle onto the cap.
    • Iterate the program once and click on the "..." icon next to the inRectangle. In the editor draw a small rectangle (about 15x15 pixels should be enough) roughly in the center of the cap.
    • Make sure you put the rectangle on the same bottle where the coordinate system is.
    • The result should look like the image below. Notice how the coordinate system symbol is below the rectangle.
  4. Add a the LocateSingleObject_Edges1 filter. Connect the inSearchRegion input with the outAlignedRectangle output.

    • Open the edge model editor. Mark the area shown in the provided image. Use the setting from the image as well.
    • After closing the editor, change the filter properties. Set the inEdgeThreshold to 8 and the inMinScore to 0.5.
    • The inEdgeThreshold parameter determines how strong the transition between pixels must be to be considered an edge. The inMinScore parameter determines the minimum score of a valid object occurrence. In this case we are only interested in finding the orientation of the cap, so the minimum score must be relatively low.
    • By clicking on Show/Hide Ports you can show additional outputs and inputs. Check the option as shown in the following image, so that the filter has another output: outObject.isNil.Not.
    • Connect the newly created output into the the inStatus port of the view2DBox_PassFail HMI indicator. That port should correspond to the previously used inData port (step 2).
    • Now if the object is detected (orientation is correct) the created output is True and the rectangle from the previous step is green. When no object was detect (orientation was wrong, the rectangle is red.
  5. To organize the program a bit more, you can extract filters into a step macrofilters.

Macrofilter Main

Further Readings