Spaces:
Sleeping
Sleeping
TheKnight115
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -106,29 +106,28 @@ def process_video_and_save(uploaded_file):
|
|
106 |
# Dictionary to track violations per license plate
|
107 |
violations_dict = {}
|
108 |
|
109 |
-
#
|
110 |
-
video_path = "/kaggle/working/uploaded_video.mp4"
|
|
|
|
|
|
|
111 |
with open(video_path, "wb") as f:
|
112 |
f.write(uploaded_file.getbuffer())
|
113 |
|
114 |
cap = cv2.VideoCapture(video_path)
|
115 |
-
|
116 |
-
# Check if the video file opened successfully
|
117 |
if not cap.isOpened():
|
118 |
-
|
119 |
return None
|
120 |
|
121 |
-
#
|
122 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
123 |
-
output_video_path = '/kaggle/working/output_violation.mp4'
|
124 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
125 |
-
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
126 |
-
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
127 |
out = cv2.VideoWriter(output_video_path, fourcc, fps, (width, height))
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
# Process the video frame by frame
|
132 |
while cap.isOpened():
|
133 |
ret, frame = cap.read()
|
134 |
if not ret:
|
@@ -223,6 +222,8 @@ def process_video_and_save(uploaded_file):
|
|
223 |
# Release resources when done
|
224 |
cap.release()
|
225 |
out.release()
|
|
|
|
|
226 |
return output_video_path # Return the path of the processed video
|
227 |
|
228 |
|
|
|
106 |
# Dictionary to track violations per license plate
|
107 |
violations_dict = {}
|
108 |
|
109 |
+
# Paths for saving violation images and videos
|
110 |
+
video_path = "/kaggle/working/uploaded_video.mp4"
|
111 |
+
output_video_path = '/kaggle/working/output_violation.mp4'
|
112 |
+
|
113 |
+
# Save the uploaded video file to this path
|
114 |
with open(video_path, "wb") as f:
|
115 |
f.write(uploaded_file.getbuffer())
|
116 |
|
117 |
cap = cv2.VideoCapture(video_path)
|
118 |
+
|
|
|
119 |
if not cap.isOpened():
|
120 |
+
st.error("Error opening video file.")
|
121 |
return None
|
122 |
|
123 |
+
# Codec and output settings
|
124 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
|
|
125 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
126 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
127 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
128 |
out = cv2.VideoWriter(output_video_path, fourcc, fps, (width, height))
|
129 |
|
130 |
+
# Process frames
|
|
|
|
|
131 |
while cap.isOpened():
|
132 |
ret, frame = cap.read()
|
133 |
if not ret:
|
|
|
222 |
# Release resources when done
|
223 |
cap.release()
|
224 |
out.release()
|
225 |
+
if not os.path.exists(output_video_path):
|
226 |
+
st.error("Error: Processed video was not created.")
|
227 |
return output_video_path # Return the path of the processed video
|
228 |
|
229 |
|