TheKnight115 commited on
Commit
5316aad
·
verified ·
1 Parent(s): c0507c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
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
- # Video path (input)
110
- video_path = "/kaggle/working/uploaded_video.mp4" # Save the uploaded video file to this path
 
 
 
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
- print("Error opening video file")
119
  return None
120
 
121
- # Define codec and output video settings
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)) # Frame width
126
- height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # Frame height
127
  out = cv2.VideoWriter(output_video_path, fourcc, fps, (width, height))
128
 
129
- margin_y = 50
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