Certainly! Here's an updated version of the script that exports all six cubemap faces joined horizontally without spaces, in the order: X+, X-, Y+, Y-, Z+, Z-.
import cv2
import os
import numpy as np
def transform_equi_to_cubemap(input_path, output_path):
# Load the equirectangular map
equi_map = cv2.imread(input_path)
# Calculate the height and width of each face
height, width = equi_map.shape[:2]
face_width = width // 4
face_height = height // 3
# Define the center points of each face
face_centers = [
(face_width * 2.5, face_height * 1.5), # Front face (X+)
(face_width * 0.5, face_height * 1.5), # Right face (X-)
(face_width * 1.5, face_height * 0.5), # Top face (Y+)
(face_width * 1.5, face_height * 2.5), # Bottom face (Y-)
(face_width * 3.5, face_height * 1.5), # Left face (Z+)
(face_width * 4.5, face_height * 1.5) # Back face (Z-)
]
# Define the offsets for each face
face_offsets = [
(-face_width, 0), # Front face (X+)
(0, 0), # Right face (X-)
(face_width, 0), # Top face (Y+)
(face_width, 0), # Bottom face (Y-)
(-face_width * 2, 0), # Left face (Z+)
(-face_width * 3, 0) # Back face (Z-)
]
# Create the output folder if it doesn't exist
os.makedirs(output_path, exist_ok=True)
# Extract each face and concatenate them horizontally
faces = []
for i in range(6):
face_center = face_centers[i]
face_offset = face_offsets[i]
# Calculate the four corners of the face
tl = (int(face_center[0] - face_width / 2 + face_offset[0]), int(face_center[1] - face_height / 2))
tr = (int(face_center[0] + face_width / 2 + face_offset[0]), int(face_center[1] - face_height / 2))
bl = (int(face_center[0] - face_width / 2 + face_offset[0]), int(face_center[1] + face_height / 2))
br = (int(face_center[0] + face_width / 2 + face_offset[0]), int(face_center[1] + face_height / 2))
# Extract the face from the equirectangular map
face = equi_map[tl[1]:bl[1], tl[0]:tr[0]]
# Add the face to the list
faces.append(face)
# Concatenate the faces horizontally
cubemap = np.concatenate(faces, axis=1)
# Save the cubemap image
cv2.imwrite(f"{output_path}/cubemap.jpg", cubemap)
print("Transformation complete!")
# Prompt the user for input and output paths
input_path = input("Enter the path of the input equirectangular map: ")
output_path = input("Enter the path of the output folder: ")
# Call the transformation function
transform_equi_to_cubemap(input_path, output_path)
When you run the updated script, it will export a single image named cubemap.jpg containing the six joined cubemap faces in the specified output folder.