Phaneendrabayi commited on
Commit
2f4663c
·
verified ·
1 Parent(s): b6733b3

Update pages/Life_cycle_of_ML.py

Browse files
Files changed (1) hide show
  1. pages/Life_cycle_of_ML.py +24 -27
pages/Life_cycle_of_ML.py CHANGED
@@ -1018,33 +1018,30 @@ cap.release()
1018
 
1019
  # Button to start the webcam
1020
  if st.button("Start Webcam"):
1021
- stframe = st.empty() # Placeholder for the video stream
1022
-
1023
- # Open the webcam
1024
- vid = cv2.VideoCapture(0)
1025
-
1026
- if not vid.isOpened():
1027
- st.error("Webcam not accessible")
1028
- else:
1029
- while True:
1030
- success, frame = vid.read()
1031
- if not success:
1032
- st.warning("Unable to capture video frame")
1033
- break
1034
-
1035
- # Convert the frame to RGB
1036
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
1037
-
1038
- # Display the frame
1039
- stframe.image(frame, channels="RGB", use_column_width=True)
1040
-
1041
- # Exit on 'q' key press (add an escape from the loop)
1042
- if cv2.waitKey(1) & 0xFF == ord('q'):
1043
- break
1044
-
1045
- # Release webcam resources
1046
- vid.release()
1047
- cv2.destroyAllWindows()
1048
 
1049
  st.code("""
1050
  import cv2
 
1018
 
1019
  # Button to start the webcam
1020
  if st.button("Start Webcam"):
1021
+ # Get video from webcam
1022
+ cap = cv2.VideoCapture(0)
1023
+
1024
+ # Check if camera opened successfully
1025
+ if not cap.isOpened():
1026
+ st.error("Cannot open camera")
1027
+
1028
+ while True:
1029
+ # Capture frame-by-frame
1030
+ ret, frame = cap.read()
1031
+
1032
+ # If frame is not read correctly
1033
+ if not ret:
1034
+ st.error("Can't receive frame (stream end?). Exiting ...")
1035
+ break
1036
+
1037
+ # Our operations on the frame here
1038
+ gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
1039
+
1040
+ # Display the resulting frame
1041
+ st.image(gray, channels="L")
1042
+
1043
+ # When everything done, release the capture
1044
+ cap.release()
 
 
 
1045
 
1046
  st.code("""
1047
  import cv2