read in a url video stream, get each frame and apply a sharpening to it and then display it
To upload files, please first save the app
import streamlit as st
import cv2
import numpy as np
st.title("Video Stream Sharpening")
st.write("Enter a URL to a video stream to apply sharpening filter")
url = st.text_input("Video URL")
if url:
try:
# Create a sharpening kernel
kernel = np.array([[-1,-1,-1],
[-1, 9,-1],
[-1,-1,-1]])
# Open video stream
cap = cv2.VideoCapture(url)
# Create a placeholder for the video frame
frame_placeholder = st.empty()
while cap.isOpened():
ret, frame = cap.read()
if not ret:
st.error("Can't receive frame from stream. Exiting...")
break
# Convert frame from BGR to RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Apply sharpening
sharpened = cv2.filter2D(frame, -1, kernel)
# Display the frame
frame_placeholder.image(sharpened, channels="RGB", use_column_width=True)
cap.release()
except Exception as e:
st.error(f"Error processing video stream: {str(e)}")
st.write("""
### Instructions
1. Enter a URL to a video stream (e.g., RTSP, HTTP stream)
2. The app will apply a sharpening filter to each frame
3. Press Stop button to end the stream
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?