Converting 360 Spherical to Equirectangular
See ExampleScripts- convert_to_pixels
The script is designed to convert 3D eye-tracking data from Cartesian coordinates (x, y, z) to 2D coordinates on an equirectangular projection, commonly used in 360° videos or panoramic images. Specifically, it's converting these coordinates to pixel coordinates on an equirectangular frame. Here's a breakdown of what each part of the script does:
Cartesian to Spherical Coordinates:
The cartesian_to_spherical function takes 3D Cartesian coordinates (x, y, z) and converts them to spherical coordinates. In spherical coordinates, theta is the angle in the xy-plane (azimuth), and phi is the angle from the positive z-axis (inclination).
The normalization step ensures that the (x, y, z) vector is treated as a direction vector, not a position in space.
Spherical to Equirectangular Projection:
The spherical_to_equirectangular function then converts these spherical coordinates into pixel coordinates on an equirectangular projection.
theta is mapped linearly across the horizontal axis of the equirectangular frame, and phi is mapped linearly across the vertical axis.
The final output is pixel_x and pixel_y, which represent the location on the equirectangular projection where the gaze point would appear.
Application in the Script:
The script reads eye-tracking data from an input file, where each row contains the x, y, z coordinates of the gaze point, among other data.
It converts these coordinates to equirectangular projection pixel coordinates for each data point.
The output is a CSV file with the original data plus the converted pixel coordinates (pixel_x, pixel_y).
This conversion is useful when you need to map 3D gaze data onto a 2D representation of a 360° environment, such as overlaying gaze points onto a 360° video frame. The pixel coordinates tell you where on the 2D frame the person was looking, based on their 3D gaze direction.