Camera System & 3D Projection
The padelkit.camera module provides a mathematically rigorous, vectorized projective camera engine designed for padel computer vision, synthetic dataset generation, and 3D state estimation.
Coordinate Systems Overview
PadelKit connects three coordinate frames seamlessly:
- Name
1. World Frame (Meters)- Type
- (X, Y, Z)
- Description
Matches the standard
Courtgeometry system (CoordinateSystem.CENTEREDby default):(0, 0, 0)lies at the center of the net on the floor,+Xpoints right across the court width,+Ypoints forward towards the far back wall, and+Zpoints vertically upwards.
- Name
2. Camera Frame (OpenCV / CV)- Type
- (X_cam, Y_cam, Z_cam)
- Description
Origin at the optical center of the lens.
+X_campoints right across image columns,+Y_campoints down across image rows, and+Z_campoints forward along the optical axis into the court. Also exposesopengl_camera_to_world_matrix(+Yup,-Zforward) for direct compatibility with Three.js and Blender.
- Name
3. Image Sensor Plane (Pixels)- Type
- (u, v)
- Description
Origin
(0, 0)at the top-left corner of the image sensor, withuin[0, width_px]andvin[0, height_px].
Quick Example: Projecting the 17 Court Landmarks
Using a built-in broadcast camera preset, you can project all 17 3D CourtLandmark points onto a 1080p image sensor in two lines of code, and unproject any 2D pixel detection back onto the 3D court floor (Z = 0).
3D-to-2D & 2D-to-3D
from padelkit import Camera, Court
court = Court.fip_standard()
cam = Camera.broadcast_near(court=court)
# 1. Project all 17 3D landmarks to 2D image pixels
landmarks_px = cam.project_court_landmarks(court=court)
center_uv = landmarks_px["center"]
# 2. Intersect a 2D pixel ray with the court floor (Z = 0.0)
floor_xyz = cam.project_pixel_to_plane(center_uv, plane_z=0.0)
# 3. Or calibrate a Camera directly from 4+ labeled 2D landmarks in a video
cal_cam = Camera.from_landmarks({
"floor_near_left": landmarks_px["floor_near_left"],
"floor_near_right": landmarks_px["floor_near_right"],
"floor_far_right": landmarks_px["floor_far_right"],
"floor_far_left": landmarks_px["floor_far_left"],
})
Output
# center_uv (pixels)
(960.0, 567.42)
# floor_xyz (meters)
(0.0, 0.0, 0.0)
Core Camera Components
- Name
Camera- Type
- class
- Description
Top-level camera model combining
CameraIntrinsics,CameraExtrinsics, andCameraDistortion. Provides presets and projection/unprojection methods. SeeCamera.
- Name
CameraIntrinsics- Type
- dataclass
- Description
Sensor resolution (
width_px,height_px), focal lengths (fx,fy), principal point (cx,cy), and calibration matrixK. SeeCameraIntrinsics.
- Name
CameraExtrinsics- Type
- dataclass
- Description
6-DoF position and orientation in 3D space, constructible via
from_look_at(),from_euler(), orfrom_rt(). SeeCameraExtrinsics.
- Name
CameraDistortion- Type
- dataclass
- Description
Forward and iterative inverse optical distortion supporting Pinhole, Brown-Conrady (
k1, k2, p1, p2, k3), and Kannala-Brandt Fisheye (k1, k2, k3, k4) lenses. SeeCameraDistortion.