import cv2
from typing import Optional
import numpy as np

def capture_frame(device: int = 0) -> Optional[np.ndarray]:
    cap = cv2.VideoCapture(device)
    if not cap.isOpened():
        print("[WARN] Camera not found – returning placeholder")
        return np.zeros((240, 320, 3), dtype=np.uint8)   # чёрно‑белый placeholder
    ret, frame = cap.read()
    cap.release()
    return frame if ret else None
