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. Follow the steps described in the tutorials mentioned in the hints section.

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

    • Connect the outBottleAlignments output to the inAlignment input.
    • Iterate the program once. Enter the editor (click "..." next to inRectangle) and draw a rectangle of roughly the size of the cap of a bottle.
    • Drag 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.
  3. Add a CreateRectangleRegion filter. Its inRectangleAlignment input should be connect to the outBottleAlignments output.

    • In the fields inFrameWidth and inFrameHeight enter the dimensions of the analyzed images (395 and 297)
    • Iterate the program once and click on the "..." icon next to 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 LocateSingleObject_Edges filter. Connect the inSearchRegion input with the outRegion 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 inEdgeThreshold to 8 and 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 the previous filter into a step macrofilter.

Macrofilter Main

Macrofilter DetectBottles

Macrofilter CheckTopOrientations

Macrofilter CheckLiquidLevel

Macrofilter CheckFoamAbsence

Used Filters

Icon Name Description
EnumerateImages Emulates image acquisition with images stored on disk.
CreateRectangle Creates a rectangle from an aligned point.
CreateRectangleRegion Creates a region corresponding to a given rectangle.
LocateSingleObject_Edges Detection of an object whose outlines are sharp and rigid. Often one of the first filters in a program.
ScanMultipleStripes Very fast detection of multiple pairs of opposite edges - usually for counting or width measurements.
CreateCoordinateSystemFromPoint Most often used to define an object alignment from results of 1D Edge Detection or Blob Analysis.
CheckPresence_Intensity Quick and easy presence verification, e.g. for missing caps, screws, labels.
ScanSingleEdge Very fast detection of an object (e.g. horizontal displacement of a bottle) and simple measurements (e.g. liquid level in a bottle).
AlignRectangle Required when there is a rectangle defined in a local coordinate system, but the next image-related filter in the program does not have any inAlignment input.
SegmentCenter Computes the center point of a segment.

Further Readings