File size: 849 Bytes
89ca944
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)