geoai-py 0.25.0__py2.py3-none-any.whl → 0.27.0__py2.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.
- geoai/__init__.py +38 -1
- geoai/auto.py +4 -2
- geoai/change_detection.py +2 -2
- geoai/detectron2.py +4 -1
- geoai/extract.py +4 -1
- geoai/moondream.py +0 -1
- geoai/prithvi.py +1338 -0
- geoai/sam.py +2 -1
- geoai/segment.py +10 -1
- geoai/timm_regress.py +1652 -0
- geoai/utils.py +3 -1
- {geoai_py-0.25.0.dist-info → geoai_py-0.27.0.dist-info}/METADATA +4 -4
- {geoai_py-0.25.0.dist-info → geoai_py-0.27.0.dist-info}/RECORD +17 -15
- {geoai_py-0.25.0.dist-info → geoai_py-0.27.0.dist-info}/WHEEL +1 -1
- {geoai_py-0.25.0.dist-info → geoai_py-0.27.0.dist-info}/entry_points.txt +0 -0
- {geoai_py-0.25.0.dist-info → geoai_py-0.27.0.dist-info}/licenses/LICENSE +0 -0
- {geoai_py-0.25.0.dist-info → geoai_py-0.27.0.dist-info}/top_level.txt +0 -0
geoai/sam.py
CHANGED
|
@@ -5,7 +5,6 @@ The SamGeo class provides an interface for segmenting geospatial data using the
|
|
|
5
5
|
import os
|
|
6
6
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
7
7
|
|
|
8
|
-
import cv2
|
|
9
8
|
import numpy as np
|
|
10
9
|
import torch
|
|
11
10
|
from leafmap import array_to_image, blend_images
|
|
@@ -125,6 +124,7 @@ class SamGeo:
|
|
|
125
124
|
Raises:
|
|
126
125
|
ValueError: If the input source is not a valid path or numpy array.
|
|
127
126
|
"""
|
|
127
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
128
128
|
|
|
129
129
|
if isinstance(source, str):
|
|
130
130
|
if source.startswith("http"):
|
|
@@ -399,6 +399,7 @@ class SamGeo:
|
|
|
399
399
|
Raises:
|
|
400
400
|
ValueError: If no masks are available and `save_masks()` cannot generate them.
|
|
401
401
|
"""
|
|
402
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
402
403
|
import matplotlib.pyplot as plt
|
|
403
404
|
|
|
404
405
|
if self.batch:
|
geoai/segment.py
CHANGED
|
@@ -4,7 +4,6 @@ import os
|
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
6
6
|
|
|
7
|
-
import cv2
|
|
8
7
|
import geopandas as gpd
|
|
9
8
|
import numpy as np
|
|
10
9
|
import rasterio
|
|
@@ -174,6 +173,8 @@ class GroundedSAM:
|
|
|
174
173
|
Returns:
|
|
175
174
|
List[DetectionResult]: Filtered detection results.
|
|
176
175
|
"""
|
|
176
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
177
|
+
|
|
177
178
|
if not detections:
|
|
178
179
|
return detections
|
|
179
180
|
|
|
@@ -235,6 +236,8 @@ class GroundedSAM:
|
|
|
235
236
|
|
|
236
237
|
def _mask_to_polygon(self, mask: np.ndarray) -> List[List[int]]:
|
|
237
238
|
"""Convert mask to polygon coordinates."""
|
|
239
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
240
|
+
|
|
238
241
|
# Find contours in the binary mask
|
|
239
242
|
contours, _ = cv2.findContours(
|
|
240
243
|
mask.astype(np.uint8), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE
|
|
@@ -255,6 +258,8 @@ class GroundedSAM:
|
|
|
255
258
|
self, polygon: List[Tuple[int, int]], image_shape: Tuple[int, int]
|
|
256
259
|
) -> np.ndarray:
|
|
257
260
|
"""Convert polygon to mask."""
|
|
261
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
262
|
+
|
|
258
263
|
# Create an empty mask
|
|
259
264
|
mask = np.zeros(image_shape, dtype=np.uint8)
|
|
260
265
|
|
|
@@ -279,6 +284,8 @@ class GroundedSAM:
|
|
|
279
284
|
Returns:
|
|
280
285
|
List[np.ndarray]: List of individual instance masks.
|
|
281
286
|
"""
|
|
287
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
288
|
+
|
|
282
289
|
# Find connected components
|
|
283
290
|
num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(
|
|
284
291
|
mask.astype(np.uint8), connectivity=8
|
|
@@ -320,6 +327,8 @@ class GroundedSAM:
|
|
|
320
327
|
Returns:
|
|
321
328
|
List[Dict]: List of polygon dictionaries with geometry and properties.
|
|
322
329
|
"""
|
|
330
|
+
import cv2 # Lazy import to avoid QGIS opencv conflicts
|
|
331
|
+
|
|
323
332
|
polygons = []
|
|
324
333
|
|
|
325
334
|
# Get individual instances
|