| |
| |
| """ |
| Multi-Camera View Concatenation Utility |
| |
| Simple utility for concatenating three camera views: |
| - Head camera: Keep original size |
| - Left/Right wrist cameras: Resize to half and stack vertically |
| |
| """ |
| import cv2 |
| import numpy as np |
| from typing import Optional, Tuple |
|
|
|
|
| def resize_and_concatenate_frames( |
| self, |
| head_img: np.ndarray, |
| left_img: np.ndarray, |
| right_img: np.ndarray |
| ) -> Optional[np.ndarray]: |
| """ |
| Concatenate three camera views in T-shape layout: |
| - Top: Head camera (keep original size, e.g., 480x640) |
| - Bottom left: Left wrist camera (resize to half, e.g., 240x320) |
| - Bottom right: Right wrist camera (resize to half, e.g., 240x320) |
| Final output: 720x640 (height x width) |
| |
| Args: |
| head_img: Head camera image (keep original size) |
| left_img: Left wrist camera image (resize to half size) |
| right_img: Right wrist camera image (resize to half size) |
| |
| Returns: |
| Concatenated image with T-shape layout |
| """ |
| try: |
| |
| orig_h, orig_w = head_img.shape[:2] |
| |
| |
| half_h, half_w = orig_h // 2, orig_w // 2 |
| left_resized = cv2.resize(left_img, (half_w, half_h)) |
| right_resized = cv2.resize(right_img, (half_w, half_h)) |
| |
| |
| bottom_row = np.hstack([left_resized, right_resized]) |
| |
| |
| |
| |
| combined = np.vstack([head_img, bottom_row]) |
| |
| return combined |
| except Exception as e: |
| return None |
|
|
|
|
| def get_concatenated_dimensions(original_shape: Tuple[int, int]) -> Tuple[int, int]: |
| """ |
| Calculate output dimensions for concatenated frame. |
| |
| Args: |
| original_shape: (height, width) of original images |
| |
| Returns: |
| (height, width) of concatenated result |
| """ |
| h, w = original_shape |
| |
| return h, int(w * 1.5) |
|
|
|
|
| |
| if __name__ == "__main__": |
| |
| h, w = 240, 320 |
| |
| head_img = np.random.randint(0, 255, (h, w, 3), dtype=np.uint8) |
| left_img = np.random.randint(0, 255, (h, w, 3), dtype=np.uint8) |
| right_img = np.random.randint(0, 255, (h, w, 3), dtype=np.uint8) |
| |
| |
| result = resize_and_concatenate_frames(head_img, left_img, right_img) |
| |
| if result is not None: |
| print(f"Original shape: {head_img.shape}") |
| print(f"Concatenated shape: {result.shape}") |
| print(f"Expected shape: {get_concatenated_dimensions((h, w))}") |
| |
| |
| |
| else: |
| print("Concatenation failed") |
|
|