You are here: Start » Program Examples » Calibration of World Coordinates

Calibration of World Coordinates

Aim

In this example a coin must be located on the image. Then, its coordinates (image coordinates) must be converted to world coordinates and presented in mm.

Input

Set of images with calibration chessboard (for scale). Chessboard is not perpendicular to a camera, so the perspective must be removed.

Output

The position of the coin center in millimetres.

Hints

This example shows a typical problem with coupling results of vision analysis with an external device such as an industrial robot.

  • Due to perspective distortion a vision analysis cannot be done on an input image. In first step the perspective distortion must be removed using CreatePerspectiveMap_Path and then RemapImage.

  • Next a world plane must be found using a CalibrateWorldCoordinates.

  • Filter DetectSingleCircle can be used to find the coin on an undistorted image.

  • Finding the world plane and perspective correction model should be done in a separate Task macrofilter.

Solution (Studio)

  1. Create a task macrofilter and name it CreateCalibrationMaps.

  2. Select one of images and load it with LoadImage. Selected image will be the reference image for further analysis.

  3. Add filter CreatePerspectiveMap_Path and set inImagePath as on the image below.

  1. Then using a precise setting of points in the path editor create rectangle in corners:

    1. (113, 117),
    2. (463, 117),
    3. (463, 373),
    4. (113, 373).
  2. Save outSpatialMap with SaveObject to perspectiveMap.avdata.

  3. To precise selection of image points in CalibrateWorldCoordinates the background image without distortion is needed. Add filter RemapImage and connect to it outputs of LoadImage and CreatePerspectiveMap_Path.

  4. In inWorldPoints mark chessboard corners like on an image below.

  1. Store value of outWorldPlane and outResolution using a SaveObject file.

  2. Execute CreateCalibrationMaps macrofilter to create necessary avdata files.

  3. To macrofilter Main add EnumerateImages filter to load each images from images directory.

  4. Add RemapImage to remove perspective distortion from the image. Using a command ""Link From AVDATA File.." from the port's context menu link the saved SpatialMap.

  5. Add filter DetectSingleCircle and connect it to RemapImage. Set inRadius to 17.0 and inMinScore to 2.

  6. Show the outCircle.Center output.

  7. Add filter PointToWorldCoordinates and link to inWorldPlane and inResolution AVDATA files stored in previous steps.

  8. Connect the outCircle.Center to inImagePoint.

  9. Create a new empty formula with two Integer inputs inX and inY.

  10. Create an output with name outString and with formula:

"("+toString(inX)+"mm, "+toString(inY)+"mm)"

  1. Add filter DrawStrings_Palette to draw the value on an input image. Use the DrawPoints_Palette filter to draw a coin center.

Macrofilter Main uses calculated world plane and perspective model to perform vision analysis

Macrofilter CreateCalibrationMaps finds a perspective correction model and a world plane

Used Filters

Icon Name Description
EnumerateImages Emulates image acquisition with images stored on disk.
RemapImage Fast (precomputed) image transformations, especially for view undistortion or object geometry correction (e.g. pos recognition of labels on cylindrical bottles).
CalibrateWorldCoordinates Use this filter to prepare data necessary for translating image coordinates to real-world units, e.g. for robot guidance applications.
CreatePerspectiveMap_Path Data preprocessing for fast perspective correction. The result is used by RemapImage.
DrawPoints_Palette Draws points on an image with multiple colors.
DrawStrings_Palette Draws strings (text) on an image with multiple colors.
DetectSingleCircle Detection of a circular or close-to-circular object like a hole, pin, pill or particle.
LoadImage Loads a single image from a file.
PointToWorldCoordinates Usually used before passing object detection results to a robot.
SaveObject Saves an object to a file.