home/ atoms/ screen-capture-as-diffusion-input

A screen region or webcam feed can be the continuous image source for real-time img2img diffusion

StreamDiffusion’s screen capture example (examples/screen/main.py) demonstrates a live-coding VJ pattern: a translucent tkinter overlay lets the user position a capture region; mss grabs that screen rectangle every cycle at full frame rate; frames are appended to a shared list; the inference process samples from that list, runs img2img diffusion, and pushes results to an output queue displayed live. This creates a real-time feedback loop: whatever is rendered on screen gets re-diffused frame by frame according to the active text prompt. Changing the prompt live (stream.update_prompt(...)) steers the visual character of the output without interruption. The pattern generalises to any image source: webcam via OpenCV, NDI, or another application window.

Examples

# Capture from screen region:
with mss.mss() as sct:
    img = sct.grab({'top':300,'left':200,'width':512,'height':512})
    inputs.append(pil2tensor(PIL.Image.frombytes('RGB', img.size, img.bgra,'raw','BGRX')))

Assessment

Name two alternative image sources you could substitute for mss in the screen capture loop and describe what change in code would be required for each.

“img = PIL.Image.frombytes("RGB", img.size, img.bgra, "raw", "BGRX")”
corpus · streamdiffusion-pipeline-for-real-time-interactive-image-gen · chunk 33