Projection functions#

project_points

Project world-space vertices to DRTK pixel coordinates.

project_points_grad

Apply the pinhole projection Jacobian to world-space vertex deltas.

drtk.utils.projection.project_points(v, campos, camrot, focal, princpt, distortion_mode=None, distortion_coeff=None, fov=None, lut_vector_field=None, lut_spacing=None)[source]#

Project world-space vertices to DRTK pixel coordinates.

The world-to-camera convention is v_cam = camrot @ (v - campos). v_pix stores pixel x, y followed by camera-space z so it can be passed directly to drtk.rasterize(). Vertices with z <= 0 are behind the camera and are rejected by rasterization.

distortion_mode may be None/"pinhole", "radial-tangential", "fisheye", "fisheye62", or "fisheye62_lut". A per-batch list of modes is supported for pinhole, radial-tangential, and fisheye batches; Fisheye62 modes are currently supported only when distortion_mode is a single string. For Fisheye62 with fov, vertices outside the valid radius get z = -1 so any triangle touching them is culled by the rasterizer.

Parameters:
  • v – World-space vertices with shape (N, V, 3).

  • campos – Camera positions with shape (N, 3).

  • camrot – World-to-camera rotation matrices with shape (N, 3, 3).

  • focal – Camera intrinsic matrices with shape (N, 2, 2).

  • princpt – Principal points in pixels with shape (N, 2).

  • distortion_mode – Optional distortion mode string or per-batch list of mode strings.

  • distortion_coeff – Distortion coefficients. Shape depends on distortion_mode.

  • fov – Optional maximum normalized radius with shape (N, 1).

  • lut_vector_field – Optional Fisheye62 LUT offset field with shape (N, 2, H_lut, W_lut).

  • lut_spacing – Optional Fisheye62 LUT spacing with shape (N, 2).

Returns:

(v_pix, v_cam). Both tensors have shape (N, V, 3). v_pix stores (x_pixels, y_pixels, z_camera).

drtk.utils.projection.project_points_grad(v_grad, v, campos, camrot, focal, distortion_mode=None, distortion_coeff=None)[source]#

Apply the pinhole projection Jacobian to world-space vertex deltas.

This computes d project_points(v) / d v @ v_grad for the undistorted pinhole projection path. Distortion gradients are not implemented here; pass distortion_mode=None.

Parameters:
  • v_grad – World-space vertex perturbations with shape (N, V, 3).

  • v – World-space vertices with shape (N, V, 3).

  • campos – Camera positions with shape (N, 3).

  • camrot – World-to-camera rotation matrices with shape (N, 3, 3).

  • focal – Camera intrinsic matrices with shape (N, 2, 2).

  • distortion_mode – Distortion is not implemented and must be None.

  • distortion_coeff – Distortion is not implemented and must be None.

Returns:

Pixel-space perturbations with shape (N, V, 2).