File size: 1,894 Bytes
243ec99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
import cv2
import numpy as np
from camera_input_live import camera_input_live

# Set page config
st.set_page_config(page_title="Real-Time Video AI Demo", layout="wide")

# Title and description
st.title("Real-Time Video AI Processing with Streamlit")
st.write("This app demonstrates real-time webcam video processing with AI filters using Streamlit and OpenCV.")

# Sidebar for filter selection
st.sidebar.header("Filter Controls")
filter_type = st.sidebar.selectbox(
    "Choose a filter",
    ["None", "Grayscale", "Canny Edge Detection", "Blur"]
)

# Initialize the camera input
image = camera_input_live()

# Process and display the video feed
if image is not None:
    # Convert the image from bytes to numpy array
    nparr = np.frombuffer(image.getvalue(), np.uint8)
    frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    
    # Apply selected filter
    if filter_type == "Grayscale":
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        # Convert back to 3 channels for Streamlit display
        frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
    elif filter_type == "Canny Edge Detection":
        frame = cv2.Canny(frame, 100, 200)
        # Convert back to 3 channels for Streamlit display
        frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
    elif filter_type == "Blur":
        frame = cv2.GaussianBlur(frame, (15, 15), 0)
    
    # Display the processed frame
    st.image(frame, channels="RGB", caption="Live Video Feed")
else:
    st.warning("Waiting for camera input...")

# Instructions
st.sidebar.markdown("""
### Instructions
1. Allow camera access when prompted
2. Select a filter from the dropdown
3. View the processed video in real-time
4. Try different filters to see AI processing in action
""")

# Requirements note
st.sidebar.info("Make sure you have installed: streamlit, opencv-python, numpy, streamlit-camera-input-live")