Spaces:
Sleeping
Sleeping
Update pages/Data Collection.py
Browse files- pages/Data Collection.py +362 -6
pages/Data Collection.py
CHANGED
|
@@ -915,13 +915,369 @@ def image_details_page():
|
|
| 915 |
# Unstructured Data - Video Page
|
| 916 |
def video_details_page():
|
| 917 |
st.title("Unstructured Data - Video Details")
|
| 918 |
-
|
| 919 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 920 |
|
| 921 |
-
- Formats include MP4, AVI, MKV, etc.
|
| 922 |
-
- Libraries like OpenCV and MoviePy are used for video processing.
|
| 923 |
-
""")
|
| 924 |
-
st.code('import cv2\nvideo = cv2.VideoCapture("file.mp4")', language="python")
|
| 925 |
|
| 926 |
if st.button("Back to Home"):
|
| 927 |
st.session_state['page'] = "home"
|
|
|
|
| 915 |
# Unstructured Data - Video Page
|
| 916 |
def video_details_page():
|
| 917 |
st.title("Unstructured Data - Video Details")
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
# Title
|
| 921 |
+
st.markdown("""
|
| 922 |
+
<h1 style='text-align: center; color: #FF0000;'>Understanding Video and Frame Rates</h1>",
|
| 923 |
+
unsafe_allow_html=True
|
| 924 |
+
""")
|
| 925 |
+
)
|
| 926 |
+
# Definition of Video
|
| 927 |
+
st.markdown("""
|
| 928 |
+
"<h3 style='text-align: center; color: #FF0000;'>What is video?</h3>",
|
| 929 |
+
unsafe_allow_html=True
|
| 930 |
+
""")
|
| 931 |
+
|
| 932 |
+
st.write("""
|
| 933 |
+
A **video** is made up of a series of images called frames. These frames are shown one after another very quickly,
|
| 934 |
+
giving the impression of continuous motion. For example, if we have a sequence of images I1, I2, I3, ..., In,
|
| 935 |
+
the transition between them happens so fast that our eyes can't notice the individual images.
|
| 936 |
+
This fast switching between frames is what creates a video.
|
| 937 |
+
The smoothness of a video depends on how many frames are shown per second, measured in frames per second (fps):
|
| 938 |
+
- **30 fps**: 30 frames are displayed every second, which gives decent smoothness.
|
| 939 |
+
- **60 fps**: 60 frames are displayed every second, making the video smoother.
|
| 940 |
+
The higher the number of frames per second, the smoother the video will look. Fewer frames per second can make the video appear less smooth or choppy.
|
| 941 |
+
""")
|
| 942 |
+
|
| 943 |
+
st.markdown("""
|
| 944 |
+
"<h3 style='text-align: center; color: #FF0000;'>Understanding Video Processing with OpenCV</h3>",
|
| 945 |
+
unsafe_allow_html=True
|
| 946 |
+
""")
|
| 947 |
+
|
| 948 |
+
st.write("""
|
| 949 |
+
**Load the Video**
|
| 950 |
+
- OpenCV uses `cv2.VideoCapture()` to load a video file. This function takes the file path of the video and opens it so that we can work with it.
|
| 951 |
+
|
| 952 |
+
**Read Frames**
|
| 953 |
+
-To process the video, we read each individual frame. OpenCV provides a loop to go through every frame in the video. Inside the loop, the `read()` function grabs each frame until the video reaches the end.
|
| 954 |
+
|
| 955 |
+
**Display Frames**
|
| 956 |
+
-To simulate video playback, OpenCV uses `cv2.imshow()` to display each frame one by one. This function shows the images in a sequence, making it look like the video is playing.
|
| 957 |
+
|
| 958 |
+
**Exit Playback**
|
| 959 |
+
-You can exit the playback at any time by pressing a key. A common practice is to check if a specific key (like 'q') is pressed during the playback. If the key is detected, the video stops, and the program ends the loop.
|
| 960 |
+
""")
|
| 961 |
+
|
| 962 |
+
st.code("""
|
| 963 |
+
# Reading the video
|
| 964 |
+
|
| 965 |
+
vid = cv2.VideoCapture("Here give the path of the vedio")
|
| 966 |
+
|
| 967 |
+
# Dividing the video into frames and looping each and very frame by suing while loop as we dont how many frames
|
| 968 |
+
|
| 969 |
+
while True:
|
| 970 |
+
succ,img = vid.read()
|
| 971 |
+
|
| 972 |
+
if succ == False: # here if the frame doesnot exist break
|
| 973 |
+
break
|
| 974 |
+
|
| 975 |
+
cv2.imshow("Window name",img) # display the video
|
| 976 |
+
|
| 977 |
+
if cv2.waitKey(1)& 255 == ord("q"): # to interupt the vedio or to come out of video in the middle use ascii value
|
| 978 |
+
break
|
| 979 |
+
|
| 980 |
+
cv2.destroyAllWindows() # removing all the tempory memory RAM
|
| 981 |
+
""", language = "python")
|
| 982 |
+
|
| 983 |
+
|
| 984 |
+
# Use st.markdown to display the explanation
|
| 985 |
+
|
| 986 |
+
st.markdown("""
|
| 987 |
+
"<h3 style='text-align: center; color: #FF0000;'>Understanding `vid.read()`</h3>",
|
| 988 |
+
unsafe_allow_html=True
|
| 989 |
+
""")
|
| 990 |
+
|
| 991 |
+
st.markdown("""
|
| 992 |
+
- `vid.read()` is used to grab one frame (image) at a time from a video.
|
| 993 |
+
- It gives back two things:
|
| 994 |
+
1. **`succ`**: A `True` or `False` value.
|
| 995 |
+
- **`True`** means the frame was successfully loaded.
|
| 996 |
+
- **`False`** means the frame could not be loaded (usually because the video has ended).
|
| 997 |
+
2. **`img`**: The actual frame (image) from the video, which is in the form of a NumPy array. This image can then be processed just like any regular picture.
|
| 998 |
+
""")
|
| 999 |
+
|
| 1000 |
+
st.markdown("""
|
| 1001 |
+
"<h3 style='text-align: center; color: #FF0000;'>Understanding `cv2.waitkey()`</h3>",
|
| 1002 |
+
unsafe_allow_html=True
|
| 1003 |
+
""")
|
| 1004 |
+
|
| 1005 |
+
st.markdown("""
|
| 1006 |
+
|
| 1007 |
+
- **`cv2.waitKey(1)`**:
|
| 1008 |
+
- This function waits for a key to be pressed for 1 millisecond.
|
| 1009 |
+
- If a key is pressed, it returns the code of that key. If no key is pressed, it returns `-1`.
|
| 1010 |
+
|
| 1011 |
+
- **`& 255`**:
|
| 1012 |
+
- This part ensures the key code is correctly interpreted across different systems.
|
| 1013 |
+
- It keeps only the last 8 bits of the code (the actual key code).
|
| 1014 |
+
|
| 1015 |
+
- **`ord('q')`**:
|
| 1016 |
+
- This gets the ASCII value of the letter `'q'`.
|
| 1017 |
+
- The ASCII value for `'q'` is 113.
|
| 1018 |
+
- This is used to check if the user pressed the `'q'` key to stop the program.
|
| 1019 |
+
|
| 1020 |
+
""")
|
| 1021 |
+
|
| 1022 |
+
st.code("""
|
| 1023 |
+
if cv2.waitKey(1)& 255 == ord("q"):
|
| 1024 |
+
break
|
| 1025 |
+
""")
|
| 1026 |
+
|
| 1027 |
+
st.markdown("""
|
| 1028 |
+
"<h3 style='text-align: center; color: #FF0000;'>Converting BGR Video to Grayscale
|
| 1029 |
+
</h3>",
|
| 1030 |
+
unsafe_allow_html=True
|
| 1031 |
+
""")
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
|
| 1035 |
+
# Use st.markdown to display the explanation
|
| 1036 |
+
st.markdown("""
|
| 1037 |
+
You can process video frames one by one and convert them as needed. In this example, we will:
|
| 1038 |
+
|
| 1039 |
+
- Convert each frame of a video from BGR (Blue, Green, Red) color format to grayscale (a black-and-white image).
|
| 1040 |
+
- Display both the original video frames and the grayscale frames side by side.
|
| 1041 |
+
""")
|
| 1042 |
+
|
| 1043 |
+
|
| 1044 |
+
# Use st.code to display the OpenCV code
|
| 1045 |
+
st.code("""
|
| 1046 |
+
import cv2
|
| 1047 |
+
|
| 1048 |
+
# Load the video
|
| 1049 |
+
vid = cv2.VideoCapture("path of the video")
|
| 1050 |
+
|
| 1051 |
+
while True:
|
| 1052 |
+
succ, img = vid.read() # Reading the video
|
| 1053 |
+
|
| 1054 |
+
# Dividing the video into frames and looping through each frame as we don't know how many frames
|
| 1055 |
+
if succ == False: # If the frame does not exist, break
|
| 1056 |
+
break
|
| 1057 |
+
|
| 1058 |
+
img1 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Converting BGR image to Grayscale
|
| 1059 |
+
|
| 1060 |
+
cv2.imshow("video_color", img) # Display the original video
|
| 1061 |
+
|
| 1062 |
+
cv2.imshow("video_gray", img1) # Display the grayscale video
|
| 1063 |
+
|
| 1064 |
+
if cv2.waitKey(1) & 255 == ord("q"): # To interrupt the video or stop in the middle using ASCII value
|
| 1065 |
+
break
|
| 1066 |
+
|
| 1067 |
+
cv2.destroyAllWindows() # Removing all the temporary memory (RAM)
|
| 1068 |
+
""", language="python")
|
| 1069 |
+
|
| 1070 |
+
st.markdown("""
|
| 1071 |
+
"<h3 style='text-align: center; color: #FF0000;'>Splitting video into 3 Different channels (B,G,R)
|
| 1072 |
+
</h3>",
|
| 1073 |
+
unsafe_allow_html=True
|
| 1074 |
+
""")
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
+
# Use st.markdown to display the explanation
|
| 1078 |
+
st.markdown("""
|
| 1079 |
+
Each frame of a colored video consists of three channels: Blue, Green, and Red (BGR). In this example, we will:
|
| 1080 |
+
|
| 1081 |
+
- Split each frame of the video into separate Blue, Green, and Red color channels.
|
| 1082 |
+
- Display the original video alongside each individual color channel.
|
| 1083 |
+
""")
|
| 1084 |
+
|
| 1085 |
+
# Use st.code to display the OpenCV code
|
| 1086 |
+
st.code("""
|
| 1087 |
+
import cv2
|
| 1088 |
+
import numpy as np
|
| 1089 |
+
|
| 1090 |
+
# Load the video
|
| 1091 |
+
vid = cv2.VideoCapture("path of the video")
|
| 1092 |
+
|
| 1093 |
+
while True:
|
| 1094 |
+
succ, img = vid.read()
|
| 1095 |
+
|
| 1096 |
+
if succ == False:
|
| 1097 |
+
break
|
| 1098 |
+
|
| 1099 |
+
# Split the image into Blue, Green, and Red channels
|
| 1100 |
+
b, g, r = cv2.split(img)
|
| 1101 |
+
z = np.zeros(b.shape, dtype=np.uint8) # Create a blank channel
|
| 1102 |
+
|
| 1103 |
+
# Convert the image to grayscale
|
| 1104 |
+
img1 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 1105 |
+
|
| 1106 |
+
# Display the individual color channels
|
| 1107 |
+
cv2.imshow("bluechannel", cv2.merge([b, z, z]))
|
| 1108 |
+
cv2.imshow("green_channel", cv2.merge([z, g, z]))
|
| 1109 |
+
cv2.imshow("red_channel", cv2.merge([z, z, r]))
|
| 1110 |
+
|
| 1111 |
+
# Display the grayscale video
|
| 1112 |
+
cv2.imshow("video_gray", img1)
|
| 1113 |
+
|
| 1114 |
+
if cv2.waitKey(100) & 255 == ord("q"):
|
| 1115 |
+
break
|
| 1116 |
+
|
| 1117 |
+
cv2.destroyAllWindows() # Remove temporary windows
|
| 1118 |
+
""", language="python")
|
| 1119 |
+
|
| 1120 |
+
|
| 1121 |
+
st.markdown("""
|
| 1122 |
+
"<h3 style='text-align: center; color: #ffa500;'>Live Streaming with Webcam
|
| 1123 |
+
</h3>",
|
| 1124 |
+
unsafe_allow_html=True
|
| 1125 |
+
""")
|
| 1126 |
+
|
| 1127 |
+
# Display the explanation in markdown
|
| 1128 |
+
st.markdown("""
|
| 1129 |
+
|
| 1130 |
+
OpenCV allows you to use your webcam for live video streaming. The `cv2.VideoCapture()` function is used to activate the webcam. Here's how it works:
|
| 1131 |
+
|
| 1132 |
+
- `cv2.VideoCapture(0)`: The `0` tells OpenCV to use the default webcam on your computer. If you have multiple cameras, you can use other numbers (like 1, 2) to access those cameras.
|
| 1133 |
+
- This function establishes a connection with the webcam and begins capturing video frames in real time.
|
| 1134 |
+
|
| 1135 |
+
The following example demonstrates how to:
|
| 1136 |
+
- Activate the webcam.
|
| 1137 |
+
- Display the live stream.
|
| 1138 |
+
- Close the webcam window by pressing the 'p' key.
|
| 1139 |
+
""")
|
| 1140 |
+
|
| 1141 |
+
# Display the OpenCV code
|
| 1142 |
+
st.code("""
|
| 1143 |
+
import cv2
|
| 1144 |
+
|
| 1145 |
+
# Capture video from the default webcam (ID = 0)
|
| 1146 |
+
vid = cv2.VideoCapture(0)
|
| 1147 |
+
|
| 1148 |
+
while True:
|
| 1149 |
+
suc, img = vid.read()
|
| 1150 |
+
|
| 1151 |
+
if suc == False:
|
| 1152 |
+
print("Web Camera is not working")
|
| 1153 |
+
break
|
| 1154 |
+
|
| 1155 |
+
cv2.imshow("live stream", img)
|
| 1156 |
+
|
| 1157 |
+
# Exit the loop when 'p' key is pressed
|
| 1158 |
+
if cv2.waitKey(1) & 255 == ord('p'):
|
| 1159 |
+
break
|
| 1160 |
+
|
| 1161 |
+
cv2.destroyAllWindows()
|
| 1162 |
+
""", language="python")
|
| 1163 |
+
|
| 1164 |
+
st.markdown("""
|
| 1165 |
+
"<h3 style='text-align: center; color: #ffa500;'>Dual Webcam Stream `Color vs Grayscale Capture`
|
| 1166 |
+
</h3>",
|
| 1167 |
+
unsafe_allow_html=True
|
| 1168 |
+
""")
|
| 1169 |
+
|
| 1170 |
+
st.markdown("""
|
| 1171 |
+
# Opening Two Webcams: Original and Grayscale Video
|
| 1172 |
+
- 1. The first webcam displays the original video feed from the camera.
|
| 1173 |
+
- 2. The second webcam shows the same video feed, but converted to grayscale, where the color information is removed, leaving only varying shades of gray.
|
| 1174 |
+
""")
|
| 1175 |
+
|
| 1176 |
+
st.code("""
|
| 1177 |
+
vid = cv2.VideoCapture(0) # default id = 0
|
| 1178 |
+
|
| 1179 |
+
|
| 1180 |
+
while True:
|
| 1181 |
+
suc,img=vid.read()
|
| 1182 |
+
|
| 1183 |
+
if suc == False:
|
| 1184 |
+
print("Web Camera is not working")
|
| 1185 |
+
break
|
| 1186 |
+
|
| 1187 |
+
img1 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
| 1188 |
+
|
| 1189 |
+
cv2.imshow("live stream",img) # orginal stream
|
| 1190 |
+
cv2.imshow("Grayscale live stream",img1) # Gray Scale stream
|
| 1191 |
+
|
| 1192 |
+
if cv2.waitKey(1) & (255) == ord("q"):
|
| 1193 |
+
break
|
| 1194 |
+
|
| 1195 |
+
cv2.destroyAllWindows()
|
| 1196 |
+
""")
|
| 1197 |
+
st.markdown("""
|
| 1198 |
+
"<h3 style='text-align: center; color: #ffa500;'> Webcam Stream with RGB Channel Separation
|
| 1199 |
+
</h3>",
|
| 1200 |
+
unsafe_allow_html=True
|
| 1201 |
+
""")
|
| 1202 |
+
|
| 1203 |
+
|
| 1204 |
+
st.markdown("""
|
| 1205 |
+
# Split the Image into RGB Channels:
|
| 1206 |
+
- The image captured by the webcam is divided into three parts: Red, Green, and Blue. This is done using `cv2.split()`
|
| 1207 |
+
# Create Separate Channel Images:
|
| 1208 |
+
- The separate Red, Green, and Blue images are then combined back into three full-color images using `cv2.merge()`.
|
| 1209 |
+
- This lets us see each color channel on its own, but in full color.
|
| 1210 |
+
""")
|
| 1211 |
+
|
| 1212 |
+
st.code("""
|
| 1213 |
+
vid = cv2.VideoCapture(0) # default id = 0
|
| 1214 |
+
|
| 1215 |
+
|
| 1216 |
+
while True:
|
| 1217 |
+
suc,img=vid.read()
|
| 1218 |
+
|
| 1219 |
+
if suc == False:
|
| 1220 |
+
print("Web Camera is not working")
|
| 1221 |
+
break
|
| 1222 |
+
|
| 1223 |
+
b,g,r=cv2.split(img)
|
| 1224 |
+
z = np.zeros(b.shape,dtype=np.uint8)
|
| 1225 |
+
|
| 1226 |
+
|
| 1227 |
+
cv2.imshow("live stream",img)
|
| 1228 |
+
cv2.imshow("livestream1",cv2.merge([b,z,z])) # Blue channel
|
| 1229 |
+
cv2.imshow("livestream2",cv2.merge([z,g,z])) # Green channel
|
| 1230 |
+
cv2.imshow("livestream3",cv2.merge([z,z,r])) # Red channel
|
| 1231 |
+
|
| 1232 |
+
|
| 1233 |
+
|
| 1234 |
+
if cv2.waitKey(1) & (255) == ord("q"):
|
| 1235 |
+
break
|
| 1236 |
+
|
| 1237 |
+
cv2.destroyAllWindows()
|
| 1238 |
+
""")
|
| 1239 |
+
|
| 1240 |
+
st.markdown("""
|
| 1241 |
+
"<h3 style='text-align: center; color: #ffa500;'>Webcam Frame Capture and Save
|
| 1242 |
+
</h3>",
|
| 1243 |
+
unsafe_allow_html=True
|
| 1244 |
+
""")
|
| 1245 |
+
|
| 1246 |
+
|
| 1247 |
+
st.markdown("""
|
| 1248 |
+
- **Activate Webcam**: The webcam is activated automatically when the application starts.
|
| 1249 |
+
- **Capture Frames**: Press the 's' key to capture and save the current frame to the 'captured_frames' folder.
|
| 1250 |
+
- **Stop Webcam Feed**: Press the 'p' key to stop the webcam and close the application.
|
| 1251 |
+
""")
|
| 1252 |
+
|
| 1253 |
+
|
| 1254 |
+
st.code("""
|
| 1255 |
+
vid = cv2.VideoCapture(0) # default id = 0
|
| 1256 |
+
c=0
|
| 1257 |
+
|
| 1258 |
+
while True:
|
| 1259 |
+
suc,img=vid.read()
|
| 1260 |
+
|
| 1261 |
+
if suc == False:
|
| 1262 |
+
print("Web Camera is not working")
|
| 1263 |
+
break
|
| 1264 |
+
|
| 1265 |
+
cv2.imshow("video",img)
|
| 1266 |
+
|
| 1267 |
+
if cv2.waitKey(1)& (255) == ord("s"):
|
| 1268 |
+
cv2.imwrite(r"C:\Users\lenovo\Desktop\Hari\{}.jpg".format(c),img) #path to save the images
|
| 1269 |
+
print("image have been captured")
|
| 1270 |
+
c+=1
|
| 1271 |
+
|
| 1272 |
+
if cv2.waitKey(1)& (255) == ord("q"):
|
| 1273 |
+
break
|
| 1274 |
+
|
| 1275 |
+
|
| 1276 |
+
cv2.destroyAllWindows()
|
| 1277 |
+
""")
|
| 1278 |
+
|
| 1279 |
+
|
| 1280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1281 |
|
| 1282 |
if st.button("Back to Home"):
|
| 1283 |
st.session_state['page'] = "home"
|