Update pages/Life_cycle_of_ML.py
Browse files- 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 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 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
|