RiverCV is a Python library for detecting and generating river masks from imagery using foundational computer-vision models such as Segment Anything (SAM).
- Simple, high-level API for river mask generation
- SAM predictor wrapper with point and bounding-box prompts
- Utilities for loading images and saving masks
- Designed to support additional foundational CV models
pip install rivercvSAM model weights are not bundled. Download them from the
SAM repository
and pass the path when constructing SAMPredictor.
from rivercv.models import SAMPredictor
from rivercv.masks import generate_river_mask
from rivercv.utils import load_image, save_mask
# Load your image
image = load_image("path/to/river_image.jpg")
# Initialise the predictor (download weights first)
predictor = SAMPredictor(
checkpoint="sam_vit_h_4b8939.pth",
model_type="vit_h",
device="cuda", # or "cpu"
)
# Generate a river mask using a point prompt
mask = generate_river_mask(
predictor,
image,
point_coords=[[512, 256]], # click on the river
point_labels=[1], # 1 = foreground
)
# Save the result
save_mask(mask, "river_mask.png")git clone https://github.com/your-username/RiverCV.git
cd RiverCV
pip install -e ".[dev]"
pytestMIT