nagasurendra commited on
Commit
0b0a1d1
·
verified ·
1 Parent(s): c16972a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -125,7 +125,6 @@ def process_video(video, resize_width=320, resize_height=240, frame_skip=5):
125
 
126
  out_width, out_height = resize_width, resize_height
127
  output_path = "processed_output.mp4"
128
- # Try codecs in order of preference
129
  codecs = [('mp4v', '.mp4'), ('MJPG', '.avi'), ('XVID', '.avi')]
130
  out = None
131
  for codec, ext in codecs:
@@ -161,12 +160,16 @@ def process_video(video, resize_width=320, resize_height=240, frame_skip=5):
161
  if frame_count % frame_skip != 0:
162
  continue
163
  processed_frames += 1
164
- frame_start = time.time()
165
 
166
  frame = cv2.resize(frame, (out_width, out_height))
167
  results = model(frame, verbose=False, conf=0.5, iou=0.7)
168
  annotated_frame = results[0].plot()
169
 
 
 
 
 
170
  frame_detections = []
171
  for detection in results[0].boxes:
172
  cls = int(detection.cls)
@@ -175,8 +178,10 @@ def process_video(video, resize_width=320, resize_height=240, frame_skip=5):
175
  label = model.names[cls]
176
  if label != 'Crocodile': # Ignore irrelevant class
177
  frame_detections.append({"label": label, "box": box, "conf": conf})
178
- log_entries.append(f"Frame {frame_count}: Detected {label} with confidence {conf:.2f}")
179
- logging.info(f"Frame {frame_count}: Detected {label} with confidence {conf:.2f}")
 
 
180
 
181
  if frame_detections:
182
  detection_frame_count += 1
@@ -204,12 +209,14 @@ def process_video(video, resize_width=320, resize_height=240, frame_skip=5):
204
  gps_coordinates.append(gps_coord)
205
  for det in frame_detections:
206
  det["gps"] = gps_coord
 
207
  all_detections.extend(frame_detections)
208
 
209
  frame_time = (time.time() - frame_start) * 1000
210
  frame_times.append(frame_time)
211
  detection_summary = {
212
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
 
213
  "frame": frame_count,
214
  "longitudinal": sum(1 for det in frame_detections if det["label"] == "Longitudinal"),
215
  "pothole": sum(1 for det in frame_detections if det["label"] == "Pothole"),
 
125
 
126
  out_width, out_height = resize_width, resize_height
127
  output_path = "processed_output.mp4"
 
128
  codecs = [('mp4v', '.mp4'), ('MJPG', '.avi'), ('XVID', '.avi')]
129
  out = None
130
  for codec, ext in codecs:
 
160
  if frame_count % frame_skip != 0:
161
  continue
162
  processed_frames += 1
163
+ frame Cheesecake = time.time()
164
 
165
  frame = cv2.resize(frame, (out_width, out_height))
166
  results = model(frame, verbose=False, conf=0.5, iou=0.7)
167
  annotated_frame = results[0].plot()
168
 
169
+ # Calculate timestamp for the current frame
170
+ frame_timestamp = frame_count / fps if fps > 0 else 0
171
+ timestamp_str = f"{int(frame_timestamp // 60)}:{int(frame_timestamp % 60):02d}"
172
+
173
  frame_detections = []
174
  for detection in results[0].boxes:
175
  cls = int(detection.cls)
 
178
  label = model.names[cls]
179
  if label != 'Crocodile': # Ignore irrelevant class
180
  frame_detections.append({"label": label, "box": box, "conf": conf})
181
+ # Log detection with timestamp
182
+ log_message = f"Frame {frame_count} at {timestamp_str}: Detected {label} with confidence {conf:.2f}"
183
+ log_entries.append(log_message)
184
+ logging.info(log_message)
185
 
186
  if frame_detections:
187
  detection_frame_count += 1
 
209
  gps_coordinates.append(gps_coord)
210
  for det in frame_detections:
211
  det["gps"] = gps_coord
212
+ det["timestamp"] = timestamp_str # Add timestamp to detection data
213
  all_detections.extend(frame_detections)
214
 
215
  frame_time = (time.time() - frame_start) * 1000
216
  frame_times.append(frame_time)
217
  detection_summary = {
218
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
219
+ "video_timestamp": timestamp_str,
220
  "frame": frame_count,
221
  "longitudinal": sum(1 for det in frame_detections if det["label"] == "Longitudinal"),
222
  "pothole": sum(1 for det in frame_detections if det["label"] == "Pothole"),