Gainward777 commited on
Commit
e94fa52
·
verified ·
1 Parent(s): 6213eaf

Update pages/1_Live_Stream.py

Browse files
Files changed (1) hide show
  1. pages/1_Live_Stream.py +9 -8
pages/1_Live_Stream.py CHANGED
@@ -22,6 +22,12 @@ elif mode == 'Pro':
22
  live_process_frame = ProcessFrame(thresholds=thresholds, flip_frame=True)
23
  pose = get_mediapipe_pose()
24
 
 
 
 
 
 
 
25
  # Temporary file to save processed video
26
  temp_dir = tempfile.TemporaryDirectory()
27
  output_video_file = os.path.join(temp_dir.name, 'output_live.avi')
@@ -30,17 +36,16 @@ output_video_file = os.path.join(temp_dir.name, 'output_live.avi')
30
  fourcc = cv2.VideoWriter_fourcc(*'XVID')
31
  video_writer = None
32
 
33
- # Start video capture
34
- cap = cv2.VideoCapture(0)
35
  if not cap.isOpened():
36
- st.error("Unable to access the camera")
37
  else:
38
  stframe = st.empty()
39
 
40
  while True:
41
  ret, frame = cap.read()
42
  if not ret:
43
- st.error("Failed to capture video")
44
  break
45
 
46
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
@@ -55,10 +60,6 @@ else:
55
  # Display in Streamlit
56
  stframe.image(processed_frame, channels="RGB")
57
 
58
- # Stop button
59
- if st.button("Stop"):
60
- break
61
-
62
  cap.release()
63
  if video_writer:
64
  video_writer.release()
 
22
  live_process_frame = ProcessFrame(thresholds=thresholds, flip_frame=True)
23
  pose = get_mediapipe_pose()
24
 
25
+ # Input stream configuration
26
+ stream_source = st.text_input("Enter RTSP/stream URL or leave blank for default camera:", "")
27
+
28
+ if stream_source == "":
29
+ stream_source = 0 # Default to local camera
30
+
31
  # Temporary file to save processed video
32
  temp_dir = tempfile.TemporaryDirectory()
33
  output_video_file = os.path.join(temp_dir.name, 'output_live.avi')
 
36
  fourcc = cv2.VideoWriter_fourcc(*'XVID')
37
  video_writer = None
38
 
39
+ # Process video
40
+ cap = cv2.VideoCapture(stream_source)
41
  if not cap.isOpened():
42
+ st.error("Unable to access the video stream")
43
  else:
44
  stframe = st.empty()
45
 
46
  while True:
47
  ret, frame = cap.read()
48
  if not ret:
 
49
  break
50
 
51
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 
60
  # Display in Streamlit
61
  stframe.image(processed_frame, channels="RGB")
62
 
 
 
 
 
63
  cap.release()
64
  if video_writer:
65
  video_writer.release()