vision-agent 0.2.42__py3-none-any.whl → 0.2.43__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.
@@ -7,11 +7,11 @@ from importlib import resources
7
7
  from pathlib import Path
8
8
  from typing import Any, Callable, Dict, List, Tuple, Union, cast
9
9
 
10
+ import cv2
10
11
  import numpy as np
11
12
  import pandas as pd
12
13
  import requests
13
14
  from PIL import Image, ImageDraw, ImageFont
14
- from scipy.spatial import distance # type: ignore
15
15
 
16
16
  from vision_agent.tools.tool_utils import _send_inference_request
17
17
  from vision_agent.utils import extract_frames_from_video
@@ -421,10 +421,39 @@ def closest_mask_distance(mask1: np.ndarray, mask2: np.ndarray) -> float:
421
421
 
422
422
  mask1 = np.clip(mask1, 0, 1)
423
423
  mask2 = np.clip(mask2, 0, 1)
424
- mask1_points = np.transpose(np.nonzero(mask1))
425
- mask2_points = np.transpose(np.nonzero(mask2))
426
- dist_matrix = distance.cdist(mask1_points, mask2_points, "euclidean")
427
- return cast(float, np.min(dist_matrix))
424
+ contours1, _ = cv2.findContours(mask1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
425
+ contours2, _ = cv2.findContours(mask2, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
426
+ largest_contour1 = max(contours1, key=cv2.contourArea)
427
+ largest_contour2 = max(contours2, key=cv2.contourArea)
428
+ polygon1 = cv2.approxPolyDP(largest_contour1, 1.0, True)
429
+ polygon2 = cv2.approxPolyDP(largest_contour2, 1.0, True)
430
+ min_distance = np.inf
431
+
432
+ small_polygon, larger_contour = (
433
+ (polygon1, largest_contour2)
434
+ if len(largest_contour1) < len(largest_contour2)
435
+ else (polygon2, largest_contour1)
436
+ )
437
+
438
+ # For each point in the first polygon
439
+ for point in small_polygon:
440
+ # Calculate the distance to the second polygon, -1 is to invert result as point inside the polygon is positive
441
+
442
+ distance = (
443
+ cv2.pointPolygonTest(
444
+ larger_contour, (point[0, 0].item(), point[0, 1].item()), True
445
+ )
446
+ * -1
447
+ )
448
+
449
+ # If the distance is negative, the point is inside the polygon, so the distance is 0
450
+ if distance < 0:
451
+ continue
452
+ else:
453
+ # Update the minimum distance if the point is outside the polygon
454
+ min_distance = min(min_distance, distance)
455
+
456
+ return min_distance if min_distance != np.inf else 0.0
428
457
 
429
458
 
430
459
  def closest_box_distance(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vision-agent
3
- Version: 0.2.42
3
+ Version: 0.2.43
4
4
  Summary: Toolset for Vision Agent
5
5
  Author: Landing AI
6
6
  Author-email: dev@landing.ai
@@ -23,14 +23,14 @@ vision_agent/tools/__init__.py,sha256=oZa_sslb1UqEgpdWROChDcz5JHdB475ejJX78FMLYv
23
23
  vision_agent/tools/easytool_tools.py,sha256=pZc5dQlYINlV4nYbbzsDi3-wauA-fCeD2iGmJUMoUfE,47373
24
24
  vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
25
25
  vision_agent/tools/tool_utils.py,sha256=wzRacbUpqk9hhfX_Y08rL8qP0XCN2w-8IZoYLi3Upn4,869
26
- vision_agent/tools/tools.py,sha256=c6H-XxcTOGHLBQ2roXIqN8OlKaBE0HYmnrB4Y0vKL5c,23694
26
+ vision_agent/tools/tools.py,sha256=h3TlucPuk3wsQguddtnCf6_ehEuELPrbT6-GI9YZe3E,24764
27
27
  vision_agent/utils/__init__.py,sha256=Ce4yPhoWanRsnTy3X7YzZNBYYRJsrJeT7N59WUf8GZM,209
28
28
  vision_agent/utils/execute.py,sha256=losZeWbhNVlBr4xYsy5dKAslarjiKwuPsKgTmLV6zgE,19497
29
29
  vision_agent/utils/image_utils.py,sha256=_cdiS5YrLzqkq_ZgFUO897m5M4_SCIThwUy4lOklfB8,7700
30
30
  vision_agent/utils/sim.py,sha256=oUZ-6eu8Io-UNt9GXJ0XRKtP-Wc0sPWVzYGVpB2yDFk,3001
31
31
  vision_agent/utils/type_defs.py,sha256=BlI8ywWHAplC7kYWLvt4AOdnKpEW3qWEFm-GEOSkrFQ,1792
32
32
  vision_agent/utils/video.py,sha256=xTElFSFp1Jw4ulOMnk81Vxsh-9dTxcWUO6P9fzEi3AM,7653
33
- vision_agent-0.2.42.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
34
- vision_agent-0.2.42.dist-info/METADATA,sha256=2_M608mmAyjkGJY1qeMwxNQxb4kfziSqp1kvMLo1yow,6826
35
- vision_agent-0.2.42.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
36
- vision_agent-0.2.42.dist-info/RECORD,,
33
+ vision_agent-0.2.43.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
34
+ vision_agent-0.2.43.dist-info/METADATA,sha256=7z0t0gus3S4eVTl3yik6RfX9lvNGwGROSaqdbXCJeRc,6826
35
+ vision_agent-0.2.43.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
36
+ vision_agent-0.2.43.dist-info/RECORD,,