Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import os
|
|
6 |
import json
|
7 |
import logging
|
8 |
import matplotlib.pyplot as plt
|
|
|
9 |
from datetime import datetime
|
10 |
from collections import Counter
|
11 |
from typing import List, Dict, Any, Optional
|
@@ -44,7 +45,7 @@ last_metrics: Dict[str, Any] = {}
|
|
44 |
frame_count: int = 0
|
45 |
SAVE_IMAGE_INTERVAL = 1 # Save every frame with detections
|
46 |
|
47 |
-
# Detection classes (aligned with model classes, excluding 'Crocodile'
|
48 |
DETECTION_CLASSES = ["Longitudinal", "Pothole", "Transverse"]
|
49 |
|
50 |
# Debug: Check environment
|
@@ -172,7 +173,7 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
|
|
172 |
|
173 |
out_width, out_height = resize_width, resize_height
|
174 |
output_path = os.path.join(OUTPUT_DIR, "processed_output.mp4")
|
175 |
-
codecs = [('mp4v', '.mp4'), ('
|
176 |
out = None
|
177 |
for codec, ext in codecs:
|
178 |
fourcc = cv2.VideoWriter_fourcc(*codec)
|
@@ -287,12 +288,15 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
|
|
287 |
detected_counts.append(len(frame_detections))
|
288 |
all_detections.extend(frame_detections)
|
289 |
|
|
|
|
|
|
|
290 |
detection_summary = {
|
291 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
292 |
"video_timestamp": timestamp_str,
|
293 |
"frame": frame_count,
|
294 |
"gps": gps_coord,
|
295 |
-
"processing_time_ms":
|
296 |
"detections": {label: sum(1 for det in frame_detections if det["label"] == label) for label in DETECTION_CLASSES}
|
297 |
}
|
298 |
data_lake_submission["analytics"].append(detection_summary)
|
@@ -330,11 +334,11 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
|
|
330 |
|
331 |
total_time = time.time() - start_time
|
332 |
avg_frame_time = sum(frame_times) / len(frame_times) if frame_times else 0
|
333 |
-
log_entries.append(f"Output video: {output_frames} frames, {output_fps} FPS, {output_duration:.2f} seconds")
|
334 |
-
logging.info(f"Output video: {output_frames} frames, {output_fps} FPS, {output_duration:.2f} seconds")
|
335 |
log_entries.append(f"Total processing time: {total_time:.2f} seconds, Avg frame time: {avg_frame_time:.2f} ms, Detection frames: {detection_frame_count}, Output frames: {output_frame_count}")
|
336 |
logging.info(f"Total processing time: {total_time:.2f} seconds, Avg frame time: {avg_frame_time:.2f} ms, Detection frames: {detection_frame_count}, Output frames: {output_frame_count}")
|
337 |
-
print(f"Output video: {output_frames} frames, {output_fps} FPS, {output_duration:.2f} seconds")
|
338 |
print(f"Total processing time: {total_time:.2f} seconds, Avg frame time: {avg_frame_time:.2f} ms, Detection frames: {detection_frame_count}, Output frames: {output_frame_count}")
|
339 |
|
340 |
chart_path = generate_line_chart()
|
|
|
6 |
import json
|
7 |
import logging
|
8 |
import matplotlib.pyplot as plt
|
9 |
+
import csv # Added for flight logs
|
10 |
from datetime import datetime
|
11 |
from collections import Counter
|
12 |
from typing import List, Dict, Any, Optional
|
|
|
45 |
frame_count: int = 0
|
46 |
SAVE_IMAGE_INTERVAL = 1 # Save every frame with detections
|
47 |
|
48 |
+
# Detection classes (aligned with model classes, excluding 'Crocodile')
|
49 |
DETECTION_CLASSES = ["Longitudinal", "Pothole", "Transverse"]
|
50 |
|
51 |
# Debug: Check environment
|
|
|
173 |
|
174 |
out_width, out_height = resize_width, resize_height
|
175 |
output_path = os.path.join(OUTPUT_DIR, "processed_output.mp4")
|
176 |
+
codecs = [('mp4v', '.mp4'), ('XVID', '.avi'), ('MJPG', '.avi')] # Prioritize mp4v
|
177 |
out = None
|
178 |
for codec, ext in codecs:
|
179 |
fourcc = cv2.VideoWriter_fourcc(*codec)
|
|
|
288 |
detected_counts.append(len(frame_detections))
|
289 |
all_detections.extend(frame_detections)
|
290 |
|
291 |
+
frame_time = (time.time() - frame_start) * 1000
|
292 |
+
frame_times.append(frame_time) # Fixed frame time tracking
|
293 |
+
|
294 |
detection_summary = {
|
295 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
296 |
"video_timestamp": timestamp_str,
|
297 |
"frame": frame_count,
|
298 |
"gps": gps_coord,
|
299 |
+
"processing_time_ms": frame_time,
|
300 |
"detections": {label: sum(1 for det in frame_detections if det["label"] == label) for label in DETECTION_CLASSES}
|
301 |
}
|
302 |
data_lake_submission["analytics"].append(detection_summary)
|
|
|
334 |
|
335 |
total_time = time.time() - start_time
|
336 |
avg_frame_time = sum(frame_times) / len(frame_times) if frame_times else 0
|
337 |
+
log_entries.append(f"Output video: {output_frames} frames, {output_fps:.2f} FPS, {output_duration:.2f} seconds")
|
338 |
+
logging.info(f"Output video: {output_frames} frames, {output_fps:.2f} FPS, {output_duration:.2f} seconds")
|
339 |
log_entries.append(f"Total processing time: {total_time:.2f} seconds, Avg frame time: {avg_frame_time:.2f} ms, Detection frames: {detection_frame_count}, Output frames: {output_frame_count}")
|
340 |
logging.info(f"Total processing time: {total_time:.2f} seconds, Avg frame time: {avg_frame_time:.2f} ms, Detection frames: {detection_frame_count}, Output frames: {output_frame_count}")
|
341 |
+
print(f"Output video: {output_frames} frames, {output_fps:.2f} FPS, {output_duration:.2f} seconds")
|
342 |
print(f"Total processing time: {total_time:.2f} seconds, Avg frame time: {avg_frame_time:.2f} ms, Detection frames: {detection_frame_count}, Output frames: {output_frame_count}")
|
343 |
|
344 |
chart_path = generate_line_chart()
|