Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tools/video/green_screen_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from pathlib import Path
from typing import Any

import numpy as np
from PIL import Image

from tools.base_tool import (
Expand Down Expand Up @@ -248,6 +247,8 @@ def execute(self, inputs: dict[str, Any]) -> ToolResult:

def _parse_hex_color(self, hex_str: str) -> np.ndarray:
"""Parse a hex color string like '#0E172A' to an RGB numpy array."""
import numpy as np

hex_str = hex_str.lstrip("#")
r = int(hex_str[0:2], 16)
g = int(hex_str[2:4], 16)
Expand Down Expand Up @@ -318,6 +319,8 @@ def _composite_frame(
out_h: int,
) -> Image.Image:
"""Composite a single speaker frame over a background frame using the given layout."""
import numpy as np

# Create alpha mask from speaker frame
speaker_arr = np.array(speaker_img).astype(float)
dist = np.sqrt(np.sum((speaker_arr - bg_color.astype(float)) ** 2, axis=2))
Expand Down