3D Tennis Ball Trajectory Reconstruction with TCN
A multi-model tennis pipeline that reconstructs court-relative 3D ball trajectories using calibrated camera geometry, temporal ball measurements, and complementary direct-XYZ and depth-correction TCNs, alongside player context.

Tools & Skills
- TCN
- 3D Trajectory Reconstruction
- Camera Calibration
- PyTorch
- TorchScript
- Multi-Camera Vision
- Model Integration
- Temporal Modeling
- PnP
- KLT Tracking
- Sensor Synchronization
- Robust Training
- Model Evaluation
- 3D Visualization
- Rerun
- TensorBoard
- Python
- NumPy
- OpenCV
- My contribution
- Designed and implemented the temporal trajectory models, calibrated multi-model integration, diameter-based expert routing, training and export contracts, delayed frame alignment, and trajectory inspection workflow.
- Outcome
- Court-relative 3D ball trajectories with aligned player context, explicit validity, and inspectable selection between direct position estimates and geometry-constrained depth corrections.
Problem and product goal
A tennis-ball detector tells us where the ball appears in an image. Understanding its flight requires a position in the court: lateral location, distance relative to the net, and height. Those quantities support spatial playback and further analysis of trajectories and landing behavior.
I developed a trajectory reconstruction system around the existing ball, person, and court models. It aligns their observations, estimates the camera’s relationship to the court, and reconstructs the ball’s movement in metric 3D coordinates. Players appear in the same court frame, making the flight easier to interpret in its playing context.
The central challenge is depth. A known ball diameter provides a geometric depth estimate from its apparent image size, but a small size error can produce a large distance error when the ball occupies only a few pixels. Camera motion, missed detections, and transitions between detection branches introduce further inconsistencies. I combined temporal learning with explicit geometry so the system can use different estimation strategies where their assumptions are appropriate.
Challenges that shaped the architecture
| Challenge | Design response |
|---|---|
| A distant ball has a very small, noisy apparent diameter. | Use a direct camera-coordinate TCN that can learn from the history of measurements. |
| Clearer, larger ball observations carry useful geometric constraints. | Learn a bounded correction to size-derived depth while preserving the measured image ray. |
| Detection branches and camera streams use different coordinates and timestamps. | Compensate camera motion, align timestamps, reproject observations, and form one tracked measurement history. |
| The preferred estimator can change as the ball approaches or recedes. | Route between independent experts using apparent diameter with hysteresis and validity checks. |
| Temporal context introduces a delay between observing and reporting a position. | Carry source-frame indices, timestamps, and the matching camera pose through buffered output. |
Upstream perception and the TCN handoff
The upstream design below shows the dual-camera perception stage that supplies this project. Its output contains merged ball detections, court landmarks and lines, and person detections with distance estimates, associated with source frames and timestamps. The trajectory stage builds ball-feature windows from these observations and uses the court and camera geometry to decode the result into 3D.
The perception front end processes HD and 4K camera streams. Ball detection runs across full-frame, cropped, and HD branches; camera-motion compensation and coordinate transforms keep the detections tied to the original images. HD observations are aligned to the reference camera’s timestamps and projected into its coordinate system. Merging and tracking select the ball history used downstream, with optional crop-based size refinement.
The court model supplies landmarks and reconstructed lines. Camera calibration and PnP turn these correspondences into a court-relative camera pose, with plausibility checks and limited reuse of a recent valid pose. This establishes the metric reference needed to decode the ball trajectory.
The person model contributes player boxes and distance estimates. These are lifted into the shared 3D scene using camera geometry, with a ground-plane intersection available when distance is unavailable. Player estimates provide scene context; the trajectory TCNs consume the ball’s temporal measurement features. Keeping these roles explicit makes each component easier to inspect and improve.
Two temporal models with different responsibilities
Both experts use a window of normalized ball coordinates, apparent diameter, an observation mask, frames since a valid detection, and frame interval. The mask and timing features expose gaps rather than silently treating missing observations as measured points. Residual, dilated temporal convolutions combine local motion with a longer history while retaining a prediction at each sequence position.
Direct camera-coordinate expert
The direct TCN predicts camera X, camera Y, and log depth through separate output heads. Decoding log depth produces a positive distance; the calibrated camera pose then transforms the position into court coordinates.
This expert is intended for small or unreliable ball measurements, where repeatedly applying the inverse relationship between apparent size and depth can amplify noise. Its training includes center and diameter perturbations, correlated drift, missing bursts, false tracks, interpolation artifacts, and branch handoffs. The purpose is to make temporal context useful when individual observations become inconsistent.
Geometry-constrained depth-correction expert
The correction TCN predicts one bounded log-depth residual. The decoder starts from the depth implied by apparent ball size and applies the learned multiplicative correction. It preserves the observed image ray, then uses calibrated geometry to recover the court position.
The residual head starts at zero, so the initial model reproduces the analytic size-based baseline. Its training objective measures the decoded 3D error in court space, connecting the correction to the spatial quantity the application needs. The bounded residual limits how far learning can move the geometric estimate. This path requires a valid target observation and camera pose.
Routing between the experts
The two models have separate parameters, training objectives, and exported artifacts. In the dual-expert mode, both produce candidate positions before a deterministic router selects the result. Larger apparent diameters favor the correction expert; smaller ones favor direct prediction. Different entry and exit thresholds keep minor diameter fluctuations from repeatedly switching the selected expert.
Validity checks allow an available candidate to be used when the preferred one cannot be decoded. If neither candidate is valid, the output records that condition. Expert identity, routing reason, candidate trajectories, and bounce-trust status remain available for inspection. A usable trajectory estimate does not automatically make a landing event trustworthy.
System pipeline
Expand the diagram to zoom in and explore.
Inference, validation, and inspection
The inference path loads TorchScript models with adjacent manifests describing feature order, normalization, output format, coordinate policy, and output delay. The router checks that the two experts agree on their shared input and timing contracts. These checks keep training and runtime assumptions visible when models are replaced.
The convolutions are causal, while the exported models deliberately report a delayed target frame. Buffered rendering associates each position with that frame’s image and camera pose. This allows later observations to help reconstruct the target position while keeping the displayed timing honest.
I implemented TensorBoard logging, training dashboards, per-episode prediction plots, and interactive trajectory galleries to inspect development behavior. Runtime JSON and Rerun views expose the raw geometric baseline, both expert candidates, the selected trajectory, and routing changes alongside camera footage and court views. Landing-review tools support checking spatial behavior around contact. These are development and replay tools, with model validity and provenance available in the outputs.
The verification workflow covers geometry, missing measurements, causal behavior, frame delay, routing hysteresis, incompatible artifacts, and exported-output comparisons. It supports tracing a failure back to perception, alignment, camera pose, model behavior, or routing rather than judging only the final rendered path.
Capability and future evolution
The implemented pipeline reconstructs a court-relative 3D ball trajectory and places it alongside players in a shared scene. It extends the dual-camera scene-understanding work with learned temporal depth reconstruction and explicit selection between complementary estimators.
The architecture separates perception, temporal features, trajectory estimation, coordinate decoding, and inspection. This allows detectors, training corruptions, routing policy, or temporal context to evolve with product needs. Additional camera setups require matching calibration and validation; changes to model inputs require corresponding training and export updates.
Reconstruction still depends on measurement quality and camera geometry. More reliable landing decisions, longer occlusions, or downstream robot control need their own validation and integration. The current work provides an inspectable trajectory-estimation foundation for those extensions.
Evidence & demonstration
Demos & project media

TCN reconstruction of a tennis ball's 3D flight in court coordinates from sequential 2D positions, apparent diameter, and temporal features.
Video description
The published demo presents a TCN that takes a sequence of 2D ball positions (x, y), apparent ball diameter, and temporal features across video frames, and predicts 3D ball positions (X, Y, Z) in court coordinates to reconstruct the ball's flight trajectory.



