Spaces:
Sleeping
Sleeping
import gradio as gr | |
import cv2 | |
import numpy as np | |
from PIL import Image | |
def video_stream(): | |
"""Captures video feed from webcam and outputs the same stream to a different canvas.""" | |
cap = cv2.VideoCapture(0) | |
while cap.isOpened(): | |
ret, frame = cap.read() | |
if not ret: | |
break | |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
yield Image.fromarray(frame) | |
cap.release() | |
# Create Gradio App | |
with gr.Blocks() as demo: | |
gr.Markdown("## π₯ Webcam Stream with Output to a Separate Canvas") | |
webcam_feed = gr.Video(label="Live Webcam", source="webcam", streaming=True) | |
canvas_output = gr.Image(label="Canvas - Output Stream") | |
start_button = gr.Button("Start Streaming") | |
start_button.click(fn=video_stream, inputs=[], outputs=[canvas_output]) | |
demo.launch(share=True) | |