nagasurendra commited on
Commit
52b3524
·
verified ·
1 Parent(s): 20dd8c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -38,7 +38,6 @@ gps_coordinates: List[List[float]] = []
38
  last_metrics: Dict[str, Any] = {}
39
  frame_count: int = 0
40
  SAVE_IMAGE_INTERVAL = 1
41
- DETECTION_CLASSES = ["Longitudinal", "Pothole", "Transverse", "Toll gate"] # Updated for Toll gates
42
  MAX_IMAGES = 500
43
 
44
  # Model setup
@@ -63,7 +62,7 @@ model_colors = {
63
  'Toll gates': (0, 0, 255) # Blue
64
  }
65
 
66
- # Helper functions (unchanged)
67
  def zip_all_outputs(report_path: str, video_path: str, chart_path: str, map_path: str) -> str:
68
  zip_path = os.path.join(OUTPUT_DIR, f"drone_analysis_outputs_{datetime.now().strftime('%Y%m%d_%H%M%S')}.zip")
69
  try:
@@ -370,7 +369,7 @@ def generate_report(
370
  log_entries.append(f"Error: Failed to save report: {str(e)}")
371
  return ""
372
 
373
- def process_video(video, selected_model, resize_width=1920, resize_height=1080, frame_skip=10):
374
  global frame_count, last_metrics, detected_counts, detected_issues, gps_coordinates, log_entries
375
  frame_count = 0
376
  detected_counts.clear()
@@ -436,15 +435,16 @@ def process_video(video, selected_model, resize_width=1920, resize_height=1080,
436
  frame = cv2.resize(frame, (out_width, out_height))
437
  resize_times.append((time.time() - frame_start) * 1000)
438
 
439
- if not check_image_quality(frame, input_resolution):
440
- continue
 
441
 
442
  annotated_frame = frame.copy()
443
  frame_detections = []
444
  inference_start = time.time()
445
 
446
  for model_name, model in use_models.items():
447
- results = model(annotated_frame, verbose=False, conf=0.5, iou=0.7)
448
  for result in results:
449
  for box in result.boxes:
450
  x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
@@ -454,18 +454,17 @@ def process_video(video, selected_model, resize_width=1920, resize_height=1080,
454
  cv2.rectangle(annotated_frame, (x1, y1), (x2, y2), color, 2)
455
  cv2.putText(annotated_frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2)
456
 
457
- if model.names[class_id] in DETECTION_CLASSES:
458
- detection_data = {
459
- "label": model.names[class_id],
460
- "model": model_name,
461
- "box": [x1, y1, x2, y2],
462
- "conf": float(box.conf[0]),
463
- "gps": [17.385044 + (frame_count * 0.0001), 78.486671 + (frame_count * 0.0001)],
464
- "timestamp": f"{int(frame_count / fps // 60):02d}:{int(frame_count / fps % 60):02d}",
465
- "frame": frame_count,
466
- "path": os.path.join(CAPTURED_FRAMES_DIR, f"detected_{frame_count:06d}.jpg")
467
- }
468
- frame_detections.append(detection_data)
469
 
470
  inference_times.append((time.time() - inference_start) * 1000)
471
 
@@ -580,7 +579,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange")) as iface:
580
  )
581
  width_slider = gr.Slider(320, 1920, value=1920, label="Output Width", step=1)
582
  height_slider = gr.Slider(240, 1080, value=1080, label="Output Height", step=1)
583
- skip_slider = gr.Slider(1, 20, value=10, label="Frame Skip", step=1)
584
  process_btn = gr.Button("Process Video", variant="primary")
585
  with gr.Column(scale=1):
586
  metrics_output = gr.Textbox(label="Detection Metrics", lines=5, interactive=False)
 
38
  last_metrics: Dict[str, Any] = {}
39
  frame_count: int = 0
40
  SAVE_IMAGE_INTERVAL = 1
 
41
  MAX_IMAGES = 500
42
 
43
  # Model setup
 
62
  'Toll gates': (0, 0, 255) # Blue
63
  }
64
 
65
+ # Helper functions
66
  def zip_all_outputs(report_path: str, video_path: str, chart_path: str, map_path: str) -> str:
67
  zip_path = os.path.join(OUTPUT_DIR, f"drone_analysis_outputs_{datetime.now().strftime('%Y%m%d_%H%M%S')}.zip")
68
  try:
 
369
  log_entries.append(f"Error: Failed to save report: {str(e)}")
370
  return ""
371
 
372
+ def process_video(video, selected_model, resize_width=1920, resize_height=1080, frame_skip=1):
373
  global frame_count, last_metrics, detected_counts, detected_issues, gps_coordinates, log_entries
374
  frame_count = 0
375
  detected_counts.clear()
 
435
  frame = cv2.resize(frame, (out_width, out_height))
436
  resize_times.append((time.time() - frame_start) * 1000)
437
 
438
+ # Comment out quality check to process all frames
439
+ # if not check_image_quality(frame, input_resolution):
440
+ # continue
441
 
442
  annotated_frame = frame.copy()
443
  frame_detections = []
444
  inference_start = time.time()
445
 
446
  for model_name, model in use_models.items():
447
+ results = model(annotated_frame, verbose=False, conf=0.25, iou=0.45)
448
  for result in results:
449
  for box in result.boxes:
450
  x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
 
454
  cv2.rectangle(annotated_frame, (x1, y1), (x2, y2), color, 2)
455
  cv2.putText(annotated_frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2)
456
 
457
+ detection_data = {
458
+ "label": model.names[class_id],
459
+ "model": model_name,
460
+ "box": [x1, y1, x2, y2],
461
+ "conf": float(box.conf[0]),
462
+ "gps": [17.385044 + (frame_count * 0.0001), 78.486671 + (frame_count * 0.0001)],
463
+ "timestamp": f"{int(frame_count / fps // 60):02d}:{int(frame_count / fps % 60):02d}",
464
+ "frame": frame_count,
465
+ "path": os.path.join(CAPTURED_FRAMES_DIR, f"detected_{frame_count:06d}.jpg")
466
+ }
467
+ frame_detections.append(detection_data)
 
468
 
469
  inference_times.append((time.time() - inference_start) * 1000)
470
 
 
579
  )
580
  width_slider = gr.Slider(320, 1920, value=1920, label="Output Width", step=1)
581
  height_slider = gr.Slider(240, 1080, value=1080, label="Output Height", step=1)
582
+ skip_slider = gr.Slider(1, 20, value=1, label="Frame Skip", step=1)
583
  process_btn = gr.Button("Process Video", variant="primary")
584
  with gr.Column(scale=1):
585
  metrics_output = gr.Textbox(label="Detection Metrics", lines=5, interactive=False)