ModuMLTECH commited on
Commit
ff5fd92
·
verified ·
1 Parent(s): c532b5b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ def main():
7
+ st.title("Webcam Grayscale Filter")
8
+ st.write("This app applies a grayscale filter to your webcam feed.")
9
+
10
+ # Add a placeholder for the webcam feed
11
+ video_placeholder = st.empty()
12
+
13
+ # Add a stop button
14
+ stop_button = st.button("Stop")
15
+
16
+ # Start the webcam
17
+ cap = cv2.VideoCapture(0)
18
+
19
+ # Check if the webcam is opened correctly
20
+ if not cap.isOpened():
21
+ st.error("Cannot open webcam. Please check your camera connection.")
22
+ return
23
+
24
+ while cap.isOpened() and not stop_button:
25
+ # Read a frame from the webcam
26
+ ret, frame = cap.read()
27
+
28
+ if not ret:
29
+ st.error("Failed to capture image from webcam.")
30
+ break
31
+
32
+ # Convert the frame to grayscale
33
+ gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
34
+
35
+ # Convert grayscale frame to RGB for Streamlit display
36
+ # (Streamlit expects RGB images)
37
+ gray_rgb = cv2.cvtColor(gray_frame, cv2.COLOR_GRAY2RGB)
38
+
39
+ # Display the frame in the Streamlit app
40
+ video_placeholder.image(gray_rgb, channels="RGB", use_column_width=True)
41
+
42
+ # Add a small delay
43
+ if cv2.waitKey(1) & 0xFF == ord('q'):
44
+ break
45
+
46
+ # Release resources
47
+ cap.release()
48
+ cv2.destroyAllWindows()
49
+ st.write("Webcam stopped")
50
+
51
+ if __name__ == "__main__":
52
+ main()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.30.0
2
+ opencv-python-headless==4.8.1.78
3
+ numpy==1.26.2
4
+ Pillow==10.1.0