RehamAAhmed commited on
Commit
dd75250
·
verified ·
1 Parent(s): ff0e26e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -415,18 +415,39 @@ def analyze_video_sam3(video_path, text_prompts, hf_token, max_duration=8.0, pro
415
 
416
  progress(1.0, desc="Done!")
417
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  # Generate list report
419
- report_md = "# 📋 Tracked Object ID Details\n\n"
420
- report_md += "Below is the list of all tracked visual instances associated with each text concept:\n\n"
 
 
 
 
421
 
422
  for prompt in sorted(track_db.keys()):
423
  obj_ids = sorted(list(track_db[prompt]))
424
  if obj_ids:
425
  ids_str = ", ".join(f"`#{oid}`" for oid in obj_ids)
426
- report_md += f"- **{prompt.capitalize()}**: {len(obj_ids)} items (IDs: {ids_str})\n"
 
 
 
427
 
428
  if not track_db:
429
- report_md += "*No objects detected in the video for the given prompts.*"
430
 
431
  return final_output_path, report_md
432
 
 
415
 
416
  progress(1.0, desc="Done!")
417
 
418
+ # Calculate Max-Visible Count per concept (maximum visible in any single keyframe)
419
+ max_visible = defaultdict(int)
420
+ for k_idx in range(len(keyframes)):
421
+ frame_masks = masks_by_frame.get(k_idx, {})
422
+ current_visible = defaultdict(int)
423
+ for obj_id, mask in frame_masks.items():
424
+ if np.any(mask):
425
+ prompt = obj_to_prompt.get(obj_id)
426
+ if prompt:
427
+ current_visible[prompt] += 1
428
+ for prompt, count in current_visible.items():
429
+ if count > max_visible[prompt]:
430
+ max_visible[prompt] = count
431
+
432
  # Generate list report
433
+ report_md = "# 📋 Apartment Inspection & Counting Report\n\n"
434
+ report_md += "Below is the comparison between the **Total Tracked IDs** (which can double-count objects if they temporarily go out of view and get assigned a new ID) and the **Max-Visible Count** (which avoids double-counting by finding the peak number of objects visible simultaneously in a single frame):\n\n"
435
+
436
+ # Create a markdown table
437
+ report_md += "| Category | Unique Tracked IDs | Max-Visible Count | Detailed Tracking IDs |\n"
438
+ report_md += "| :--- | :---: | :---: | :--- |\n"
439
 
440
  for prompt in sorted(track_db.keys()):
441
  obj_ids = sorted(list(track_db[prompt]))
442
  if obj_ids:
443
  ids_str = ", ".join(f"`#{oid}`" for oid in obj_ids)
444
+ tracked_count = len(obj_ids)
445
+ max_vis = max_visible.get(prompt, 0)
446
+ category_name = prompt.capitalize()
447
+ report_md += f"| **{category_name}** | {tracked_count} | **{max_vis}** | {ids_str} |\n"
448
 
449
  if not track_db:
450
+ report_md += "\n*No objects detected in the video for the given prompts.*"
451
 
452
  return final_output_path, report_md
453