Skip to content

šŸ Geometric Computer Vision Library for Spatial AI

docs: link relevant API docstrings to the conventions guides (#4501)

victorwon2001616107300851
diff --git a/changelog.d/4501.added.md b/changelog.d/4501.added.md
new file mode 100644
index 000000000..9a8d6b168
--- /dev/null
+++ b/changelog.d/4501.added.md
@@ -0,0 +1 @@
+Relevant camera and image-coordinate API docstrings now link directly to the camera and general conventions guides.
diff --git a/kornia/geometry/calibration/distort.py b/kornia/geometry/calibration/distort.py
index 2313cc61f..a57d27bc5 100644
--- a/kornia/geometry/calibration/distort.py
+++ b/kornia/geometry/calibration/distort.py
@@ -119,6 +119,9 @@ def distort_points(
distortion models are considered in this function.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera-intrinsics and
+ integer pixel-centre conventions used here.
+
- ``points`` are **pixel** coordinates in ``(u, v)`` order and so is the result. Pixel centres lie at
integer coordinates: the top-left centre is ``(0, 0)``.
:func:`~kornia.geometry.camera.distort_points_affine` and
diff --git a/kornia/geometry/calibration/undistort.py b/kornia/geometry/calibration/undistort.py
index 9e33e9ef0..9033ac397 100644
--- a/kornia/geometry/calibration/undistort.py
+++ b/kornia/geometry/calibration/undistort.py
@@ -42,6 +42,9 @@ def undistort_points(
distortion models are considered in this function.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera-intrinsics and
+ integer pixel-centre conventions used here.
+
- ``points`` are **pixel** coordinates in ``(u, v)`` order and so is the result. Pixel centres lie at
integer coordinates: the top-left centre is ``(0, 0)``.
- ``dist`` follows the coefficient layout documented on
@@ -175,6 +178,10 @@ def undistort_image(image: torch.Tensor, K: torch.Tensor, dist: torch.Tensor) ->
distortion models are considered in this function.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for pixel centres and camera
+ intrinsics, and :doc:`Conventions & Pitfalls </get-started/conventions>` for sampling and
+ ``align_corners`` guidance.
+
- The leading dimensions of ``image`` (everything in front of ``C, H, W``), of ``K`` (in front of its
:math:`3 \times 3` block) and of ``dist`` (in front of its ``n`` coefficients) must match exactly.
They may be empty, a single batch axis, or several axes deep, including with non-zero tilt and under
diff --git a/kornia/geometry/camera/perspective.py b/kornia/geometry/camera/perspective.py
index e23a64491..98536efd7 100644
--- a/kornia/geometry/camera/perspective.py
+++ b/kornia/geometry/camera/perspective.py
@@ -39,6 +39,9 @@ def project_points(point_3d: torch.Tensor, camera_matrix: torch.Tensor) -> torch
- a point with ``z = 0`` does not raise: the perspective divide is skipped and ``K`` is applied to the
undivided point, giving ``fx x + cx``. A point behind the camera is projected just as silently.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for camera-frame coordinates,
+ intrinsics and the pixel-centre convention.
+
.. warning::
The ``z = 0`` answer is tracked in `#4267 <https://github.com/kornia/kornia/issues/4267>`_.
@@ -83,6 +86,9 @@ def unproject_points(
- ``depth`` is the camera-frame ``z`` of the result. With ``normalize=True`` it is read as the
Euclidean ray length instead, so the result has that norm and a smaller ``z``.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for camera-frame depth,
+ intrinsics and the pixel-centre convention.
+
Args:
point_2d: tensor containing the 2d points to be projected to
the camera frame. The shape of the tensor can be :math:`(*, 2)`.
diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.py
index 8d0bdd4ed..1ff311f2c 100644
--- a/kornia/geometry/camera/pinhole.py
+++ b/kornia/geometry/camera/pinhole.py
@@ -318,6 +318,9 @@ class PinholeCamera:
- with a floating-point ``scale_factor``, an integer ``height`` / ``width`` is promoted to floating
point, unlike :meth:`scale_`. An integer factor preserves the integer image-size dtype.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for image resizing and
+ the matching intrinsics scaling convention.
+
.. warning::
The ``cx' = s * cx`` rule disagrees with the integer pixel centres the rest of the library
enumerates; it is tracked as a coordinated repair in
@@ -356,6 +359,9 @@ class PinholeCamera:
If ``height`` is integer, both image dimensions are unchanged; if only ``width`` is integer,
``height`` has already been scaled too.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for image resizing and
+ the matching intrinsics scaling convention.
+
.. warning::
The failure on an integer image size with a floating-point scale factor is tracked in
`#4265 <https://github.com/kornia/kornia/issues/4265>`_, and the principal-point rule shared with
diff --git a/kornia/geometry/camera/stereo.py b/kornia/geometry/camera/stereo.py
index 5bbd08938..cd4a5ae60 100644
--- a/kornia/geometry/camera/stereo.py
+++ b/kornia/geometry/camera/stereo.py
@@ -82,6 +82,9 @@ class StereoCamera:
- ``u`` is the **column** index and ``v`` the **row** index, as in ``cv2.reprojectImageTo3D``:
:math:`X = (u - c_x) Z / f_x` and :math:`Y = (v - c_y) Z / f_y`.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the shared intrinsics,
+ depth and integer pixel-centre conventions.
+
.. warning::
Several of the constructor guards do not enforce the contract above. A differing ``cx`` is
**rejected**, even though :attr:`cx_left` and :attr:`cx_right` are exposed separately and
diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.py
index 7edc7a626..d6cf49d66 100644
--- a/kornia/geometry/conversions.py
+++ b/kornia/geometry/conversions.py
@@ -1466,6 +1466,9 @@ def normalize_pixel_coordinates(
r"""Map pixel coordinates so that the first and last pixel of each axis become -1 and 1.
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for the library-wide pixel-centre,
+ normalized-coordinate and ``align_corners`` conventions.
+
- ``pixel_coordinates`` is :math:`(*, 2)` in ``(x, y)`` order: ``x``
indexes columns and is scaled by ``width``, ``y`` indexes rows and is
scaled by ``height``. The positional argument order is the other way
@@ -1564,6 +1567,9 @@ def denormalize_pixel_coordinates(
The input is assumed to be -1 if on extreme left, 1 if on extreme right (x = w-1).
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for the library-wide pixel-centre,
+ normalized-coordinate and ``align_corners`` conventions.
+
- the inverse of
:func:`~kornia.geometry.conversions.normalize_pixel_coordinates`,
``x = (width - 1) * (x_norm + 1) / 2``, with the same ``(x, y)``
@@ -2450,6 +2456,9 @@ def normalize_points_with_intrinsics(point_2d: torch.Tensor, camera_matrix: torc
"""Normalize points with intrinsics. Useful for conversion of keypoints to be used with essential matrix.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera intrinsics and
+ pixel-centre conventions used by these coordinates.
+
- ``point_2d`` is :math:`(*, 2)` in pixel ``(u, v)`` order and
``camera_matrix`` is a row-major pinhole :math:`(*, 3, 3)` with
``fx = K[0, 0]``, ``fy = K[1, 1]``, ``cx = K[0, 2]``, ``cy = K[1, 2]``
@@ -2495,6 +2504,9 @@ def denormalize_points_with_intrinsics(point_2d_norm: torch.Tensor, camera_matri
"""Denormalize points with intrinsics. Useful for converting normalized camera points back to pixels.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera intrinsics and
+ pixel-centre conventions used by these coordinates.
+
- the inverse of
:func:`~kornia.geometry.conversions.normalize_points_with_intrinsics`,
which documents the ``K`` layout: ``u = x * fx + cx`` and
@@ -2656,6 +2668,9 @@ def camtoworld_graphics_to_vision_4x4(extrinsics_graphics: torch.Tensor) -> torc
Vision convention: [+x, +y, +z] == [right, down, forwards].
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the graphics/vision camera
+ frames and camera-to-world extrinsics convention.
+
- the input is a **camera-to-world** pose :math:`(B, 4, 4)`: its 3x3
block maps camera axes into the world and its last column is the
camera centre in world coordinates
@@ -2739,6 +2754,9 @@ def camtoworld_graphics_to_vision_Rt(R: torch.Tensor, t: torch.Tensor) -> tuple[
Vision convention: [+x, +y, +z] == [right, down, forwards].
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the graphics/vision camera
+ frames and camera-to-world extrinsics convention.
+
- the split-argument form of
:func:`~kornia.geometry.conversions.camtoworld_graphics_to_vision_4x4`,
which documents the flip, the two camera frames, the involution and
@@ -2785,6 +2803,9 @@ def camtoworld_vision_to_graphics_4x4(extrinsics_vision: torch.Tensor) -> torch.
Vision convention: [+x, +y, +z] == [right, down, forwards].
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the graphics/vision camera
+ frames and camera-to-world extrinsics convention.
+
- the same map as
:func:`~kornia.geometry.conversions.camtoworld_graphics_to_vision_4x4`,
which carries the canonical block: ``diag(1, -1, -1, 1)`` is its own
@@ -2827,6 +2848,9 @@ def camtoworld_vision_to_graphics_Rt(R: torch.Tensor, t: torch.Tensor) -> tuple[
Vision convention: [+x, +y, +z] == [right, down, forwards].
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the graphics/vision camera
+ frames and camera-to-world extrinsics convention.
+
- the split-argument form of
:func:`~kornia.geometry.conversions.camtoworld_vision_to_graphics_4x4`
and, because ``diag(1, -1, -1, 1)`` is its own inverse, bitwise the
@@ -2869,6 +2893,9 @@ def camtoworld_to_worldtocam_Rt(R: torch.Tensor, t: torch.Tensor) -> tuple[torch
long-url: https://colmap.github.io/format.html#output-format
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for camera-to-world versus
+ world-to-camera extrinsics and camera-centre semantics.
+
- the returned pair is exactly ``(R^T, -R^T @ t)`` — the **rigid**
inverse, computed by transposition and never by a matrix inverse. For
a proper rotation that is the true inverse as a map, and in floating
@@ -2952,6 +2979,9 @@ def worldtocam_to_camtoworld_Rt(R: torch.Tensor, t: torch.Tensor) -> tuple[torch
r"""Convert worldtocam frame used in Colmap to camtoworld.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for camera-to-world versus
+ world-to-camera extrinsics and camera-centre semantics.
+
- bitwise the **same function** as
:func:`~kornia.geometry.conversions.camtoworld_to_worldtocam_Rt`,
which carries the canonical block: for a proper rotation
@@ -2998,6 +3028,9 @@ def ARKitQTVecs_to_ColmapQTVecs(qvec: torch.Tensor, tvec: torch.Tensor) -> tuple
Both poses in quaternion representation.
Convention:
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera frames and
+ extrinsics conventions composed by this conversion.
+
(every measured figure in this block — the 16-digit "as computed"
literals included — is a sample of one build, torch 2.9.1 on cpu, not
a bound; trailing digits and turnover points may move with the
diff --git a/kornia/geometry/depth.py b/kornia/geometry/depth.py
index cedc0159a..6f1b5ea04 100644
--- a/kornia/geometry/depth.py
+++ b/kornia/geometry/depth.py
@@ -81,6 +81,9 @@ def unproject_meshgrid(
:func:`~kornia.geometry.depth.depth_to_3d_v2` needs when its depth is a Euclidean ray length rather
than a camera-frame ``z``.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for pixel centres,
+ camera-frame depth and the intrinsics convention used by these rays.
+
Args:
height: height of image.
width: width of image.
@@ -152,6 +155,9 @@ def depth_to_3d_v2(
the same result when ``xyz_grid`` is what
:func:`~kornia.geometry.depth.unproject_meshgrid` returns for the same camera.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the pixel-centre,
+ camera-frame depth and intrinsics conventions used here.
+
Args:
depth: image tensor containing a depth value per pixel with shape :math:`(*, H, W)`.
camera_matrix: tensor containing the camera intrinsics with shape :math:`(*, 3, 3)`.
@@ -213,6 +219,9 @@ def depth_to_3d(depth: torch.Tensor, camera_matrix: torch.Tensor, normalize_poin
- an integer ``depth`` map is promoted through arithmetic with ``camera_matrix``: with floating-point
intrinsics the point cloud follows their dtype (for example, ``float32`` or ``float64``).
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the pixel-centre,
+ camera-frame depth and intrinsics conventions used here.
+
Args:
depth: image tensor containing a depth value per pixel with shape :math:`(B, 1, H, W)`.
camera_matrix: tensor containing the camera intrinsics with shape :math:`(B, 3, 3)`.
@@ -413,6 +422,9 @@ def warp_frame_depth(
can be nonzero; samples whose entire interpolation footprint is outside return 0.
- the result carries ``image_src``'s channel count, whatever it is: the output is :math:`(B, D, H, W)`.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera-frame,
+ depth and intrinsics conventions composed by this warp.
+
.. warning::
:class:`~kornia.geometry.depth.DepthWarper` performs the same warp under the **opposite** naming: the
frame this function calls ``dst`` (the one holding the depth) is that class's ``src``, and the image it
@@ -503,6 +515,9 @@ class DepthWarper(nn.Module):
calls :meth:`compute_projection_matrix` and forwards -- and returns a result equal to it bit for bit.
It exposes ``align_corners`` only; ``mode`` and ``padding_mode`` keep their defaults there.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the camera/world-frame,
+ intrinsics and pixel-centre conventions used by this class.
+
.. warning::
:func:`~kornia.geometry.depth.warp_frame_depth` performs the same warp under the **opposite** naming.
The frame this class calls ``src``, the one holding the depth, is that function's ``dst``
diff --git a/kornia/geometry/grid.py b/kornia/geometry/grid.py
index ddf579919..76bf8c246 100644
--- a/kornia/geometry/grid.py
+++ b/kornia/geometry/grid.py
@@ -39,6 +39,9 @@ def create_meshgrid(
produces a correspondingly empty grid; this differs from pixel-coordinate
normalization, where a zero-sized coordinate system is undefined.
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for the library-wide pixel-centre and
+ normalized-coordinate conventions used by this grid.
+
Args:
height: the image height (rows).
width: the image width (cols).
diff --git a/kornia/geometry/transform/affwarp.py b/kornia/geometry/transform/affwarp.py
index 064089a37..cdb607d29 100644
--- a/kornia/geometry/transform/affwarp.py
+++ b/kornia/geometry/transform/affwarp.py
@@ -598,6 +598,10 @@ def resize(
.. image:: _static/img/resize.png
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for sampling and ``align_corners``
+ conventions. When resizing camera images, see
+ :doc:`camera and world conventions </get-started/camera-conventions>` for matching intrinsics scaling.
+
- input: :math:`(*, H, W)`; ``size`` is ``(h, w)``
- align_corners: ``None`` by default (follows ``torch.nn.functional.interpolate``;
note :func:`warp_perspective`/:func:`rotate` default ``True``)
@@ -788,6 +792,10 @@ class Resize(nn.Module):
r"""Resize the input torch.Tensor to the given size.
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for sampling and ``align_corners``
+ conventions. When resizing camera images, see
+ :doc:`camera and world conventions </get-started/camera-conventions>` for matching intrinsics scaling.
+
- align_corners: ``None`` by default, matching :func:`resize`
- See the convention block of :func:`resize`.
diff --git a/kornia/geometry/transform/homography_warper.py b/kornia/geometry/transform/homography_warper.py
index a601c05a3..1e5071436 100644
--- a/kornia/geometry/transform/homography_warper.py
+++ b/kornia/geometry/transform/homography_warper.py
@@ -82,6 +82,9 @@ class HomographyWarper(BaseWarper):
X_{src} = H_{src}^{\{dst\}} * X_{dst}
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for homography direction, normalized
+ coordinates and sampling conventions.
+
- align_corners: ``False`` by default, matching :func:`homography_warp`
- See the convention block of :func:`homography_warp`.
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index 331b7de39..24c2c5f8e 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -223,6 +223,9 @@ def warp_perspective(
\right )
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for transform direction, pixel centres,
+ normalized coordinates and ``align_corners`` sampling rules.
+
- input: :math:`(B, C, H, W)`; ``dsize`` is ``(h, w)``
- ``M`` is the source→destination **pixel** homography :math:`(B, 3, 3)`
(contrast :func:`homography_warp`, which by default consumes destination→source normalized)
@@ -341,6 +344,9 @@ def warp_affine(
where :math:`M^{-1}` is the inverse of the :math:`3 \times 3` homogeneous extension of ``M``.
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for transform direction, pixel centres,
+ normalized coordinates and ``align_corners`` sampling rules.
+
- input: :math:`(B, C, H, W)`; ``dsize`` is ``(h, w)``
- ``M`` is the source→destination **pixel** affine matrix :math:`(B, 2, 3)`
- coordinates: ``(x, y)``, pixel centers, origin at top-left
@@ -1691,6 +1697,9 @@ def homography_warp(
See :class:`~kornia.geometry.transform.HomographyWarper` for details.
Convention:
+ See :doc:`Conventions & Pitfalls </get-started/conventions>` for homography direction, normalized
+ coordinates and ``align_corners`` sampling rules.
+
- input: :math:`(N, C, H, W)`
- ``src_homo_dst`` is the destination→source homography :math:`(N, 3, 3)`, in normalized
:math:`[-1, 1]` coordinates by default (``normalized_coordinates=True``), when
diff --git a/kornia/sensors/camera/camera_model.py b/kornia/sensors/camera/camera_model.py
index a257aa3d1..8e1587e6f 100644
--- a/kornia/sensors/camera/camera_model.py
+++ b/kornia/sensors/camera/camera_model.py
@@ -159,6 +159,9 @@ class CameraModelBase:
are kept separate by design -- this one takes ``Vector`` objects, that one plain tensors -- which is
recorded in `#4274 <https://github.com/kornia/kornia/issues/4274>`_.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the shared pixel-centre,
+ depth and intrinsics conventions across the camera APIs.
+
Example:
>>> params = torch.Tensor([328., 328., 320., 240.])
>>> cam = CameraModelBase(AffineTransform(), Z1Projection(), ImageSize(480, 640), params)
@@ -307,6 +310,8 @@ class PinholeModel(CameraModelBase):
r"""Class to represent Pinhole Camera Model.
See the Convention block on :class:`~kornia.sensors.camera.CameraModelBase`.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the corresponding camera
+ frame, depth, pixel-centre and intrinsics conventions.
The pinhole camera model describes the mathematical relationship between
the coordinates of a point in three-dimensional space and its projection
@@ -369,6 +374,9 @@ class PinholeModel(CameraModelBase):
``scale_factor``: ``fx' = s * fx`` and ``cx' = s * cx``, the half-pixel rule, which is the rule
:meth:`~kornia.geometry.camera.pinhole.PinholeCamera.scale` applies as well.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for image resizing and
+ the matching intrinsics scaling convention.
+
.. warning::
``cx' = s * cx`` disagrees with the integer pixel centres the rest of the library enumerates, and
a tensor ``scale_factor`` rebuilds ``image_size`` with 0-dim tensors in the promoted dtype
@@ -400,7 +408,11 @@ class PinholeModel(CameraModelBase):
class BrownConradyModel(CameraModelBase):
- """Brown Conrady Camera Model."""
+ """Brown Conrady Camera Model.
+
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for shared intrinsics,
+ pixel-centre and camera-frame conventions.
+ """
def __init__(self, image_size: ImageSize, params: torch.Tensor) -> None:
"""Construct BrownConradyModel class.
@@ -419,7 +431,11 @@ class BrownConradyModel(CameraModelBase):
class KannalaBrandtK3(CameraModelBase):
- """Kannala Brandt K3 Camera Model."""
+ """Kannala Brandt K3 Camera Model.
+
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for shared intrinsics,
+ pixel-centre and camera-frame conventions.
+ """
def __init__(self, image_size: ImageSize, params: torch.Tensor) -> None:
"""Construct KannalaBrandtK3 class.
@@ -435,7 +451,11 @@ class KannalaBrandtK3(CameraModelBase):
class Orthographic(CameraModelBase):
- """Orthographic Camera Model."""
+ """Orthographic Camera Model.
+
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for shared intrinsics,
+ pixel-centre and camera-frame conventions.
+ """
def __init__(self, image_size: ImageSize, params: torch.Tensor) -> None:
"""Construct Orthographic class.
@@ -457,6 +477,8 @@ class CameraModel:
r"""Class to represent camera models.
See the Convention block on :class:`~kornia.sensors.camera.CameraModelBase`.
+ See :doc:`camera and world conventions </get-started/camera-conventions>` for the corresponding camera
+ frame, depth, pixel-centre and intrinsics conventions.
Example:
>>> # Pinhole Camera Model