Building an AI Crop Monitoring Pipeline: From Satellite Imagery to Leaf-Level Inference
Learn how to build an automated AI crop monitoring tool using free Sentinel-2 multispectral data and computer vision for leaf-level disease detection.
Agricultural AI does not require a fleet of custom drones or millions in hardware capital. You can build a functioning crop stress detection service this weekend using free public satellite data, Python, and a lightweight computer vision model.
Commercial players like Taranis have raised over $100M running high-end leaf-level scouting, but most independent agronomy consultants and mid-sized family farms are priced out of those enterprise platforms. According to USDA field studies, localized pest and fungal infestations cost row-crop farmers between $35 and $65 per acre in yield reduction when detected late. Yet, the majority of regional growers still rely on walking random transects across hundreds of acres on foot.
Here is how to build an automated pipeline that detects field anomalies from orbit and classifies leaf-level crop diseases on the ground.
Sourcing Free Multispectral Imagery via STAC APIs
You do not need to buy imagery from Planet Labs or Maxar to detect crop vigor. The European Space Agency's Sentinel-2 constellation provides 10-meter spatial resolution across 13 spectral bands every five days at zero cost.
Instead of manually downloading gigabytes from web portals, query the Microsoft Planetary Computer SpatioTemporal Asset Catalog (STAC) API. We target two specific bands:
- Band 4 (Red, 665 nm): Absorbed by healthy chlorophyll.
- Band 8 (Near-Infrared / NIR, 842 nm): Reflected strongly by healthy plant cellular structures.
Here is the Python script to fetch cloud-filtered Sentinel-2 assets for any field boundary:
import pystac_client
import planetary_computer
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=planetary_computer.sign_inplace,
)
# Bounding box for the target field [min_lon, min_lat, max_lon, max_lat]
aoi_bbox = [-93.65, 41.58, -93.60, 41.62]
search = catalog.search(
collections=["sentinel-2-l2a"],
bbox=aoi_bbox,
datetime="2026-06-01/2026-07-01",
query={"eo:cloud_cover": {"lt": 15}},
)
items = list(search.item_collection())
if items:
selected_item = items[0]
red_uri = selected_item.assets["B04"].href
nir_uri = selected_item.assets["B08"].href
print(f"Retrieved assets from capture date: {selected_item.datetime}")
Run this on a cron schedule once a week. When a fresh capture with low cloud cover appears, push the raster URLs straight to your processing worker.
Calculating NDVI and Flagging Crop Anomalies with Python
Once you have the Red and NIR arrays, calculate the Normalized Difference Vegetation Index (NDVI):
$$\text{NDVI} = \frac{\text{NIR} - \text{Red}}{\text{NIR} + \text{Red}}$$
NDVI values range from -1.0 to +1.0. Dense, thriving vegetation produces scores between 0.6 and 0.85. Bare soil hovers around 0.1 to 0.2. Water yields negative numbers.
Load the GeoTIFF assets using rasterio, mask the boundaries using the farm's GeoJSON field polygon, and identify sudden drops in NDVI:
import numpy as np
import rasterio
def calculate_ndvi_anomaly(red_path, nir_path, baseline_ndvi=0.72):
with rasterio.open(red_path) as red_src:
red = red_src.read(1).astype(np.float32)
with rasterio.open(nir_path) as nir_src:
nir = nir_src.read(1).astype(np.float32)
# Prevent division by zero
denominator = nir + red
denominator[denominator == 0] = np.nan
ndvi = (nir - red) / denominator
# Flag stressed pixels: healthy expected, but dropping below threshold
stress_mask = (ndvi < 0.45) & (ndvi > 0.15)
stressed_pixel_count = np.count_nonzero(stress_mask)
return ndvi, stressed_pixel_count
If the stressed pixel cluster exceeds 5% of a field's total area over two consecutive captures, your system automatically generates an inspection alert with exact GPS coordinates for the farmer's smartphone.
Leaf-Level Disease Classification with Fine-Tuned Models
Satellite imagery tells growers where plants are dying; it cannot tell them why. Nitrogen deficiency, Southern corn rust, and root rot look identical at 10-meter resolution.
To bridge this gap, build a mobile capture endpoint where field scouts snap close-up photos of leaves at the flagged satellite coordinates. Run these images through a fine-tuned vision model trained on public ag datasets like PlantVillage or the USDA Pest and Crop Scans.
A fine-tuned YOLOv11 nano model (yolo11n.pt) is small enough to run inference on a $5/month Hetzner VPS or directly on a mobile device via ONNX Runtime without server latency:
from ultralytics import YOLO
import cv2
# Load custom model fine-tuned on maize diseases
model = YOLO("weights/maize_pathology_yolo11n.pt")
def analyze_leaf(image_path):
results = model.predict(source=image_path, conf=0.6, imgsz=640)
detections = []
for box in results[0].boxes:
class_id = int(box.cls[0])
confidence = float(box.conf[0])
label = model.names[class_id]
detections.append({"disease": label, "confidence": round(confidence, 2)})
return detections
When I analyze AgTech search volumes and buyer intent data on oppfinder.app, high-margin opportunities rarely come from selling massive "all-in-one farm operating systems." The software that actually sells solves this precise handoff: satellite anomaly alerts routed directly to a point-and-shoot leaf diagnostician that generates an actionable chemical application plan.
Packaging the Pipeline into a Sellable Micro-Service
To monetize this, skip complex subscription dashboards initially. Farmers spend their working hours inside pickup trucks and combines, not looking at web portals. Package this tool as an automated communication loop:
- Onboarding: The user draws their field boundary on a map interface (using Leaflet.js or Mapbox) and enters their phone number.
- Weekly Satellite Audit: Every Monday at 6:00 AM, query the Planetary Computer STAC endpoint for new Sentinel-2 rasters.
- MMS Dispatch: If an NDVI drop is detected, send a Twilio MMS containing an aerial heatmap showing the exact GPS spot of the stress zone.
- Infield Diagnostic: The scout walks to the pinned location, takes a leaf photo, and texts it back to the same number. Your webhook executes the YOLO model and replies with the diagnosis and herbicide recommendations in under three seconds.
Charging $250 to $500 per month for an agronomist managing 5,000 acres is trivial compared to the cost of manual crop scouts or lost yield from a fast-moving fungal outbreak.
Pick a single commodity crop grown in your region—such as corn, soybeans, or wheat. Download 200 images of that crop's three most prevalent fungal diseases from the PlantVillage dataset, train a YOLOv11 nano model on a free Google Colab T4 GPU, and wire it to a simple FastAPI backend before writing another line of front-end code.
Related Resources: