Implementation:CARLA simulator Carla Spectator Transform Tool
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Debugging, Utility |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
Command-line utility script that retrieves and prints the spectator camera transform, with options for waypoint snapping, ground projection, height adjustment, and interpolation format output.
Description
This script (spectator_transform.py) captures the current spectator camera position and orientation in a running CARLA simulation. It offers several modes: direct transform retrieval (default), waypoint snapping (-w/--use-waypoint) which returns the nearest driving waypoint to the spectator, and ground projection (-p/--use-projection) which projects the spectator position onto the ground surface using world.ground_projection(). The -z/--height-diff argument adds a vertical offset to the output position. The --interpolation-format flag (-if) outputs the transform as an XML-style point element compatible with the interpolate_camera.py script. The script also visualizes the output location with a green debug point (Color(0,100,0)) for 30 seconds.
Usage
Use this tool when navigating the CARLA world in spectator mode to record points of interest, create camera interpolation paths, or determine ground-level coordinates for spawning actors.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/util/spectator_transform.py
Signature
def main():
"""Get spectator transform with optional waypoint/projection modes."""
# Modes: direct, waypoint (-w), projection (-p)
# Optional: height diff (-z), interpolation format (-if)
Import
# Run as a command-line tool:
python spectator_transform.py
python spectator_transform.py -w -z 2
I/O Contract
| Argument | Type | Default | Description |
|---|---|---|---|
| --host | str | localhost | CARLA server IP address |
| --port | int | 2000 | CARLA server TCP port |
| -w, --use-waypoint | flag | False | Snap to nearest driving waypoint |
| -p, --use-projection | flag | False | Project onto ground surface |
| -z, --height-diff | int | 0 | Add height offset to output (meters) |
| -if, --interpolation-format | flag | False | Output as XML interpolation point |
| Output Mode | Format |
|---|---|
| Default | carla.Transform string representation |
| Interpolation | <point time="0" x="..." y="..." z="..." pitch="..." yaw="..." roll="..."/> |
Usage Examples
# Print current spectator transform
python spectator_transform.py
# Get nearest road waypoint
python spectator_transform.py -w
# Get ground projection with 3m height offset
python spectator_transform.py -p -z 3
# Output in interpolation format for camera paths
python spectator_transform.py -if