pysdic.compute_rays#
- compute_rays(image_points, intrinsic, distortion, extrinsic, *, intrinsic_kwargs=None, distortion_kwargs=None, extrinsic_kwargs=None)[source]#
Compute the rays emitted from the camera to the scene through the given image points.
\[\begin{split}\vec{x}_d &= \text{Intrinsic}^{-1}(\vec{x}_i) \\ \vec{x}_n &= \text{Distortion}^{-1}(\vec{x}_d) \\ \text{rays} &= \text{Extrinsic.compute\_rays}(\vec{x}_n)\end{split}\]Where:
\(\vec{x}_i\) are the 2D image points in the image coordinate system.
\(\vec{x}_d\) are the 2D distorted points in the normalized coordinate system.
\(\vec{x}_n\) are the 2D normalized points in the normalized coordinate system.
The normalized points are computed with
pysdic.undistort_points(), then the extrinsic transformation builds the rays in the world coordinate system with itscompute_raysmethod (the origin and the unit direction of each ray, seepysdic.Rays).Important
The extrinsic transformation must implement a
compute_rays(normalized_points, **kwargs)method returning apysdic.Raysobject, aspysdic.PerspectiveExtrinsic,pysdic.OrthographicExtrinsicandpysdic.NoExtrinsic.Note
The image points can be obtained from the pixel points \((u, v)\) by swapping the axes.
See also
Class
pysdic.Raysfor the structure of the rays.Function
pysdic.undistort_points()for the computation of the normalized points.
- Parameters:
image_points (ArrayLike) – The 2D image points in the image coordinate system. Shape \((\dots, 2)\).
intrinsic (Optional[Transformation]) – The intrinsic transformation (2D to 2D), inverted on the image points. If None, no intrinsic is applied (identity).
distortion (Optional[Transformation]) – The distortion transformation (2D to 2D), inverted on the distorted points. If None, no distortion is applied (identity).
extrinsic (Optional[Transformation]) – The extrinsic transformation with a
compute_raysmethod. If None,pysdic.NoExtrinsicis used (rays parallel to the \(z\) axis).intrinsic_kwargs (Optional[Dict[str, Any]], optional (default:
None)) – Additional keyword arguments passed to theinvertmethod of the intrinsic transformation.distortion_kwargs (Optional[Dict[str, Any]], optional (default:
None)) – Additional keyword arguments passed to theinvertmethod of the distortion transformation.extrinsic_kwargs (Optional[Dict[str, Any]], optional (default:
None)) – Additional keyword arguments passed to thecompute_raysmethod of the extrinsic transformation.
- Returns:
The rays in the world coordinate system, with shape \((\dots, 6)\).
- Return type:
Examples
Throw a ray through each pixel of an image:
import numpy from pysdic import compute_rays, PinholeIntrinsic, BrownDistortion, PerspectiveExtrinsic height, width = 480, 640 intrinsic = PinholeIntrinsic.from_matrix([[1000.0, 0.0, width / 2], [0.0, 1000.0, height / 2], [0.0, 0.0, 1.0]]) distortion = BrownDistortion([0.1, -0.05, 0.0, 0.0, 0.0]) extrinsic = PerspectiveExtrinsic.from_rt(rvec=[0.1, 0.2, 0.3], tvec=[0.0, 0.0, 5.0]) y, x = numpy.indices((height, width)) image_points = numpy.stack((x, y), axis=-1) # (H, W, 2) with (x, y) = (column, row) rays = compute_rays(image_points, intrinsic, distortion, extrinsic) rays.origins # (H, W, 3) rays.directions # (H, W, 3)