, coefK=1.0, aspect=1.0, out=None, dtype=None)[source]

Simple lens correction.

Lens correction for a spherical lenses with distortion centered at the middle of the display. See references[1]_ for implementation details.

  • xys (array_like) – Nx2 list of vertex positions or texture coordinates to distort. Assumes the output will be rendered to normalized device coordinates where points range from -1.0 to 1.0.

  • coefK (float) – Distortion coefficent. Use positive numbers for pincushion distortion and negative for barrel distortion.

  • aspect (float) – Aspect ratio of the target window or buffer (width / height).

  • out (ndarray, optional) – Optional output array. Must be same shape and dtype as the expected output if out was not specified.

  • dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.


Array of distorted vertices.

Return type




Lens Distortion White Paper, Andersson Technologies LLC, (obtained 07/28/2020)


Creating a lens correction mesh with barrel distortion (eg. for HMDs):

vertices, textureCoords, normals, faces = gltools.createMeshGrid(
    subdiv=11, tessMode='center')

# recompute vertex positions
vertices[:, :2] = mt.lensCorrection2(vertices[:, :2], coefK=2.0)

Back to top