In [ ]:
Copied!
# %pip install geoai-py
# %pip install geoai-py
Import libraries¶
In [ ]:
Copied!
import geoai
import geoai
Download sample data¶
We will download a sample image from Hugging Face Hub to use for parking spot detection. You can find more high-resolution images from OpenAerialMap.
In [ ]:
Copied!
raster_url = (
"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/parking_spots.tif"
)
raster_url = (
"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/parking_spots.tif"
)
In [ ]:
Copied!
raster_path = geoai.download_file(raster_url)
raster_path = geoai.download_file(raster_url)
Visualize the image¶
In [ ]:
Copied!
geoai.view_raster(raster_url)
geoai.view_raster(raster_url)
Initialize the model¶
In [ ]:
Copied!
detector = geoai.ParkingSplotDetector()
detector = geoai.ParkingSplotDetector()
Extract parking spots¶
Extract parking spots from the image using the model and save the output image.
In [ ]:
Copied!
mask_path = detector.generate_masks(
raster_path=raster_path,
output_path="parking_masks.tif",
confidence_threshold=0.5,
mask_threshold=0.5,
overlap=0.25,
chip_size=(256, 256),
min_object_area=10,
# max_object_area=5000,
)
mask_path = detector.generate_masks(
raster_path=raster_path,
output_path="parking_masks.tif",
confidence_threshold=0.5,
mask_threshold=0.5,
overlap=0.25,
chip_size=(256, 256),
min_object_area=10,
# max_object_area=5000,
)
Convert the image masks to polygons and save the output GeoJSON file.
In [ ]:
Copied!
gdf = detector.vectorize_masks(
masks_path="parking_masks.tif",
output_path="parking.geojson",
min_object_area=300,
# max_object_area=5000,
)
gdf = detector.vectorize_masks(
masks_path="parking_masks.tif",
output_path="parking.geojson",
min_object_area=300,
# max_object_area=5000,
)
Add geometric properties¶
In [ ]:
Copied!
gdf = geoai.add_geometric_properties(gdf)
gdf = geoai.add_geometric_properties(gdf)
Visualize results¶
In [ ]:
Copied!
geoai.view_vector_interactive(gdf, column="confidence", tiles=raster_url)
geoai.view_vector_interactive(gdf, column="confidence", tiles=raster_url)