matrice 1.0.99270__py3-none-any.whl → 1.0.99271__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -536,44 +536,44 @@ class ProximityUseCase(BaseProcessor):
536
536
  }
537
537
  })
538
538
  if zone_analysis:
539
- human_text_lines = []
540
- current_timestamp = self._get_current_timestamp_str(stream_info, frame_id=frame_id)
541
- start_timestamp = self._get_start_timestamp_str(stream_info)
542
- human_text_lines.append(f"CURRENT FRAME @ {current_timestamp}:")
543
-
544
- def robust_zone_total(zone_count):
545
- if isinstance(zone_count, dict):
546
- total = 0
547
- for v in zone_count.values():
548
- if isinstance(v, int):
549
- total += v
550
- elif isinstance(v, list) and total == 0:
551
- total += len(v)
552
- return total
553
- elif isinstance(zone_count, list):
554
- return len(zone_count)
555
- elif isinstance(zone_count, int):
556
- return zone_count
557
- else:
558
- return 0
559
-
560
- human_text_lines.append(f"\t- People Detected: {total_people}")
561
- human_text_lines.append("")
562
- human_text_lines.append(f"TOTAL SINCE @ {start_timestamp}:")
539
+ human_text_lines = []
540
+ current_timestamp = self._get_current_timestamp_str(stream_info, frame_id=frame_id)
541
+ start_timestamp = self._get_start_timestamp_str(stream_info)
542
+ human_text_lines.append(f"CURRENT FRAME @ {current_timestamp}:")
543
+
544
+ def robust_zone_total(zone_count):
545
+ if isinstance(zone_count, dict):
546
+ total = 0
547
+ for v in zone_count.values():
548
+ if isinstance(v, int):
549
+ total += v
550
+ elif isinstance(v, list) and total == 0:
551
+ total += len(v)
552
+ return total
553
+ elif isinstance(zone_count, list):
554
+ return len(zone_count)
555
+ elif isinstance(zone_count, int):
556
+ return zone_count
557
+ else:
558
+ return 0
563
559
 
564
- for zone_name, zone_count in zone_analysis.items():
565
- zone_total = robust_zone_total(zone_count)
566
- human_text_lines.append(f"\t- Zone name: {zone_name}")
560
+ human_text_lines.append(f"\t- People Detected: {total_people}")
561
+ human_text_lines.append("")
562
+ human_text_lines.append(f"TOTAL SINCE @ {start_timestamp}:")
563
+
564
+ for zone_name, zone_count in zone_analysis.items():
565
+ zone_total = robust_zone_total(zone_count)
566
+ human_text_lines.append(f"\t- Zone name: {zone_name}")
567
567
  human_text_lines.append(f"\t\t- Total count in zone: {zone_total}")
568
568
 
569
- if total_unique_count > 0:
570
- human_text_lines.append(f"\t- Total unique people in the scene: {total_unique_count}")
571
- if alerts:
572
- for alert in alerts:
573
- human_text_lines.append(f"Alerts: {alert.get('settings', {})} sent @ {current_timestamp}")
574
- else:
575
- human_text_lines.append("Alerts: None")
576
- human_text = "\n".join(human_text_lines)
569
+ if total_unique_count > 0:
570
+ human_text_lines.append(f"\t- Total unique people in the scene: {total_unique_count}")
571
+ if alerts:
572
+ for alert in alerts:
573
+ human_text_lines.append(f"Alerts: {alert.get('settings', {})} sent @ {current_timestamp}")
574
+ else:
575
+ human_text_lines.append("Alerts: None")
576
+ human_text = "\n".join(human_text_lines)
577
577
  else:
578
578
  human_text = self._generate_human_text_for_tracking(total_people, detections, total_unique_count, config, frame_id, alerts, stream_info)
579
579
 
@@ -629,7 +629,7 @@ class ProximityUseCase(BaseProcessor):
629
629
  for det in detections:
630
630
  bbox = _to_xyxy(det.get("bounding_box", det.get("bbox", {})))
631
631
  if not bbox:
632
- continue
632
+ continue
633
633
  tracked_detections.append({
634
634
  "track_id": det.get("track_id"),
635
635
  "bbox": bbox,
@@ -639,45 +639,57 @@ class ProximityUseCase(BaseProcessor):
639
639
  # IoU-NMS to remove overlapping boxes, keep highest confidence
640
640
  kept: List[Dict[str, Any]] = self._nms_by_iou(tracked_detections, overlap_iou_threshold)
641
641
 
642
- # Compute centroids
643
- centroids: Dict[Any, tuple] = {}
642
+ # Compute centroids and keep alignment arrays for IDs
643
+ centroids: List[tuple] = []
644
+ track_ids: List[Any] = []
644
645
  for td in kept:
645
646
  x1, y1, x2, y2 = map(float, td["bbox"])
647
+ # Use box center (matching your reference snippet); switch to bottom-center if needed
646
648
  cx, cy = (x1 + x2) / 2.0, (y1 + y2) / 2.0
647
- centroids[td.get("track_id")] = (cx, cy)
648
-
649
- # Build current frame proximity pairs using track IDs only when both exist
650
- current_pairs: Set[tuple] = set()
651
- ids_list = [tid for tid in centroids.keys() if tid is not None]
652
- for i in range(len(ids_list)):
653
- for j in range(i + 1, len(ids_list)):
654
- id1, id2 = ids_list[i], ids_list[j]
655
- cx1, cy1 = centroids[id1]
656
- cx2, cy2 = centroids[id2]
649
+ centroids.append((cx, cy))
650
+ track_ids.append(td.get("track_id"))
651
+
652
+ n = len(centroids)
653
+ current_pairs_by_ids: Set[tuple] = set()
654
+ current_pairs_all: Set[tuple] = set()
655
+
656
+ # Build current frame proximity pairs for all detections (even without IDs)
657
+ for i in range(n):
658
+ cx1, cy1 = centroids[i]
659
+ for j in range(i + 1, n):
660
+ cx2, cy2 = centroids[j]
657
661
  pixel_distance = math.hypot(cx1 - cx2, cy1 - cy2)
658
662
 
659
- is_close = False
660
663
  if meters_per_pixel:
661
664
  meters_distance = pixel_distance * float(meters_per_pixel)
662
665
  is_close = meters_distance < float(threshold_meters)
663
666
  else:
664
667
  is_close = pixel_distance < float(threshold_pixels_fallback)
665
668
 
666
- if is_close:
667
- pair = (id1, id2) if id1 <= id2 else (id2, id1)
668
- current_pairs.add(pair)
669
+ if not is_close:
670
+ continue
671
+
672
+ # For per-frame count, include every close pair
673
+ current_pairs_all.add((i, j))
669
674
 
670
- # Update global unique proximity pairs
671
- new_unique_pairs = {frozenset(p) for p in current_pairs} - self._observed_proximity_pairs
675
+ # For global unique, require both IDs
676
+ id_i = track_ids[i]
677
+ id_j = track_ids[j]
678
+ if id_i is not None and id_j is not None:
679
+ pair_ids = (id_i, id_j) if id_i <= id_j else (id_j, id_i)
680
+ current_pairs_by_ids.add(pair_ids)
681
+
682
+ # Update global unique proximity pairs using ID pairs only
683
+ new_unique_pairs = {frozenset(p) for p in current_pairs_by_ids} - self._observed_proximity_pairs
672
684
  if new_unique_pairs:
673
685
  self._total_proximity_count += len(new_unique_pairs)
674
686
  self._observed_proximity_pairs.update(new_unique_pairs)
675
687
 
676
- # Store last frame pairs
677
- self._last_frame_proximity_pairs = current_pairs
688
+ # Store last frame pairs (ID pairs if available, else index pairs as fallback)
689
+ self._last_frame_proximity_pairs = current_pairs_by_ids if current_pairs_by_ids else current_pairs_all
678
690
 
679
- # Return count of unique pairs in current frame
680
- return len(current_pairs)
691
+ # Return count of pairs detected in the current frame
692
+ return len(current_pairs_by_ids) if current_pairs_by_ids else len(current_pairs_all)
681
693
 
682
694
  def _nms_by_iou(self, detections: List[Dict[str, Any]], iou_threshold: float) -> List[Dict[str, Any]]:
683
695
  """Perform simple IoU-based NMS on a list of detections.
@@ -741,12 +753,12 @@ class ProximityUseCase(BaseProcessor):
741
753
  return None
742
754
 
743
755
  def _generate_human_text_for_tracking(
744
- self,
745
- total_people: int,
746
- detections,
747
- total_unique_count: int,
748
- config: ProximityConfig,
749
- frame_id: str,
756
+ self,
757
+ total_people: int,
758
+ detections,
759
+ total_unique_count: int,
760
+ config: ProximityConfig,
761
+ frame_id: str,
750
762
  alerts: Any = None,
751
763
  stream_info: Optional[Dict[str, Any]] = None) -> str:
752
764
  """Generate human-readable text for tracking stats in old format."""
@@ -765,12 +777,8 @@ class ProximityUseCase(BaseProcessor):
765
777
  human_text_lines.append("\t- No Proximity Events Detected")
766
778
 
767
779
  human_text_lines.append("")
768
- if proximity_count > 0:
769
- human_text_lines.append(f"TOTAL SINCE @ {start_timestamp}:")
770
- # If tracking IDs are available, _total_proximity_count already includes this frame's new pairs
771
- # Otherwise, fall back to showing the current frame's count
772
- total_unique = self._total_proximity_count if self._total_proximity_count > 0 else proximity_count
773
- human_text_lines.append(f"\t- Total Proximity Count: {total_unique}")
780
+ human_text_lines.append(f"TOTAL SINCE @ {start_timestamp}:")
781
+ human_text_lines.append(f"\t- Total Proximity Count: {self._total_proximity_count}")
774
782
 
775
783
  if alerts:
776
784
  for alert in alerts:
@@ -1405,12 +1413,12 @@ class ProximityUseCase(BaseProcessor):
1405
1413
  return datetime.now(timezone.utc).strftime("%Y-%m-%d-%H:%M:%S.%f UTC")
1406
1414
 
1407
1415
  if stream_info.get("input_settings", {}).get("start_frame", "na") != "na":
1408
- if frame_id:
1409
- start_time = int(frame_id)/stream_info.get("input_settings", {}).get("original_fps", 30)
1410
- else:
1411
- start_time = stream_info.get("input_settings", {}).get("start_frame", 30)/stream_info.get("input_settings", {}).get("original_fps", 30)
1412
- stream_time_str = self._format_timestamp_for_video(start_time)
1413
- return stream_time_str
1416
+ if frame_id:
1417
+ start_time = int(frame_id)/stream_info.get("input_settings", {}).get("original_fps", 30)
1418
+ else:
1419
+ start_time = stream_info.get("input_settings", {}).get("start_frame", 30)/stream_info.get("input_settings", {}).get("original_fps", 30)
1420
+ stream_time_str = self._format_timestamp_for_video(start_time)
1421
+ return stream_time_str
1414
1422
  else:
1415
1423
  # For streams, use stream_time from stream_info
1416
1424
  stream_time_str = stream_info.get("input_settings", {}).get("stream_info", {}).get("stream_time", "")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matrice
3
- Version: 1.0.99270
3
+ Version: 1.0.99271
4
4
  Summary: SDK for connecting to matrice.ai services
5
5
  Home-page: https://github.com/matrice-ai/python-sdk
6
6
  Author: Matrice.ai
@@ -204,7 +204,7 @@ matrice/deploy/utils/post_processing/usecases/plaque_segmentation_img.py,sha256=
204
204
  matrice/deploy/utils/post_processing/usecases/pothole_segmentation.py,sha256=jXTb8ZqInp5xJ-O3Zp3zQBiryFVD0-WBbhW6Kux_NDo,44905
205
205
  matrice/deploy/utils/post_processing/usecases/ppe_compliance.py,sha256=G9P9j9E9nfNJInHJxmK1Lb4daFBlG5hq0aqotTLvFFE,30146
206
206
  matrice/deploy/utils/post_processing/usecases/price_tag_detection.py,sha256=09Tp6MGAHh95s-NSAp-4WC9iCc20sajWApuUBAvgXiQ,39880
207
- matrice/deploy/utils/post_processing/usecases/proximity_detection.py,sha256=EBpu9tR_OOPfES0lM-YzBJN4FMwxc31TRKMS4OSLg4k,86507
207
+ matrice/deploy/utils/post_processing/usecases/proximity_detection.py,sha256=tbERNzbuczj1GSLwApxt6_T3sYodFh8roThrPhj-OUI,87022
208
208
  matrice/deploy/utils/post_processing/usecases/road_lane_detection.py,sha256=V_KxwBtAHSNkyoH8sXw-U-P3J8ToXtX3ncc69gn6Tds,31591
209
209
  matrice/deploy/utils/post_processing/usecases/road_traffic_density.py,sha256=YiHQ0kKhXglagHPvygywxMqZAw8s0WharrBQqLQj2q4,40311
210
210
  matrice/deploy/utils/post_processing/usecases/road_view_segmentation.py,sha256=BcBbOOg5622KuvzKrzs9cJW1wkRoIIcOab0N7BONQKQ,44986
@@ -243,8 +243,8 @@ matrice/deployment/camera_manager.py,sha256=e1Lc81RJP5wUWRdTgHO6tMWF9BkBdHOSVyx3
243
243
  matrice/deployment/deployment.py,sha256=HFt151eWq6iqIAMsQvurpV2WNxW6Cx_gIUVfnVy5SWE,48093
244
244
  matrice/deployment/inference_pipeline.py,sha256=6b4Mm3-qt-Zy0BeiJfFQdImOn3FzdNCY-7ET7Rp8PMk,37911
245
245
  matrice/deployment/streaming_gateway_manager.py,sha256=ifYGl3g25wyU39HwhPQyI2OgF3M6oIqKMWt8RXtMxY8,21401
246
- matrice-1.0.99270.dist-info/licenses/LICENSE.txt,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
247
- matrice-1.0.99270.dist-info/METADATA,sha256=oBNUFZl4QKsG87Nbl2m9QwrbUSzHoKLMSEKZ3l9VMQI,14624
248
- matrice-1.0.99270.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
249
- matrice-1.0.99270.dist-info/top_level.txt,sha256=P97js8ur6o5ClRqMH3Cjoab_NqbJ6sOQ3rJmVzKBvMc,8
250
- matrice-1.0.99270.dist-info/RECORD,,
246
+ matrice-1.0.99271.dist-info/licenses/LICENSE.txt,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
247
+ matrice-1.0.99271.dist-info/METADATA,sha256=KGoqAjTGhMEnZY1dF18S3l9f_ZK1Vn7EICyPlTbDkcg,14624
248
+ matrice-1.0.99271.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
249
+ matrice-1.0.99271.dist-info/top_level.txt,sha256=P97js8ur6o5ClRqMH3Cjoab_NqbJ6sOQ3rJmVzKBvMc,8
250
+ matrice-1.0.99271.dist-info/RECORD,,