File size: 834 Bytes
0cef02f
 
 
2d6fc22
0cef02f
a991bc1
 
2d6fc22
 
 
 
 
d395597
 
2d6fc22
 
f1e3f4b
 
758c1a1
 
e1a4884
a991bc1
 
2ec7210
80a5ad2
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
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", format="mp4", 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)