Implementation:CARLA simulator Carla Interpolate Camera Example
| Knowledge Sources | |
|---|---|
| Domains | Camera Control, Example Scripts |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
A Python example script that smoothly moves the CARLA spectator camera along an interpolated path defined by keypoints in an XML file.
Description
This script reads camera keypoints from an XML file using parse_key_points(file, id), which extracts time, location (x, y, z), and rotation (pitch, yaw, roll) data for a specified interpolation ID. The interpolate_data(points, max_order) function performs temporal interpolation using scipy.interpolate.interp1d with adaptive interpolation order (cubic, quadratic, linear, or zero depending on available points and the specified max_order). It handles angle normalization to prevent discontinuities at 360-degree boundaries. The interpolated transforms are discretized at 30 FPS. The main() function connects to a CARLA server, optionally enables synchronous mode, and either drives the spectator through the interpolated path or renders debug visualization (keypoints, interpolated points with rotation arrows, and speed annotations). Command-line arguments control host, port, XML file path, interpolation ID, start time, sync mode, and debug visualization.
Usage
Use this script to create cinematic camera flyovers or to replay predefined camera movements in CARLA for recording demonstrations, screenshots, or visual debugging.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/examples/interpolate_camera.py
Signature
def parse_key_points(file, id):
"""Parse XML keypoints for the given interpolation id."""
def interpolate_data(points, max_order):
"""Interpolate keypoints into a list of carla.Transform at 30 FPS."""
def main():
"""Connect to CARLA and animate spectator camera."""
Import
# Run as standalone script
python interpolate_camera.py -f keypoints.xml --id camera1
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --host | str | No | CARLA server IP (default: 127.0.0.1) |
| --port | int | No | CARLA server port (default: 2000) |
| --file | str | Yes | Path to XML keypoints file |
| --id | str | Yes | Interpolation ID within the XML file |
| --start-time | int | No | Starting time offset in seconds (default: 0) |
| --sync | flag | No | Enable synchronous mode |
| --debug | flag | No | Visualize keypoints and interpolation data |
Outputs
| Name | Type | Description |
|---|---|---|
| Camera animation | Visual | Spectator camera follows interpolated path |
| Debug visualization | Visual | Keypoints, arrows, and speed annotations drawn in world |
Usage Examples
# Run from command line
# python interpolate_camera.py -f camera_path.xml --id flyover1 --sync
# XML keypoint format:
# <interpolations>
# <interpolation id="flyover1" order="3">
# <point time="0" x="0" y="0" z="50" pitch="-90" yaw="0" roll="0"/>
# <point time="5" x="100" y="0" z="50" pitch="-45" yaw="0" roll="0"/>
# <point time="10" x="200" y="50" z="30" pitch="-15" yaw="45" roll="0"/>
# </interpolation>
# </interpolations>