Good research code is scripted, seeded and versioned, so that someone else (or you in a year) can rerun the experiment and get the same numbers. Python with OpenCV, scikit-learn and GeoPandas covers most of the pipeline from image to map.
Key concepts
Confusion matrix
Counts of true/false positives and negatives per class; the basis of precision, recall and F1.
Reproducibility
Fix random seeds, keep the train/test split in a file, version the data and the code, and record package versions.
Synthetic data
When ground truth is hard to get, as with 20–30 m UAV images, artificial datasets with known answers can test a method systematically; we used 120 of them.
Geospatial output
Detections only become useful for machines when they are projected to coordinates and exported as shapefiles or GeoJSON.
Code examples
Precision, recall and F1 from true/false positives and negatives
precision = tp / (tp + fp) # how many detections were right
recall = tp / (tp + fn) # how many real objects were found
f1 = 2 * precision * recall / (precision + recall)
From detections to a spray-zone shapefile (sketch)
import geopandas as gpd
from shapely.geometry import Point
# coords: weed positions in a projected CRS (metres); EOV (EPSG:23700) is common in Hungary
pts = gpd.GeoDataFrame(geometry=[Point(x, y) for x, y in coords], crs="EPSG:23700")
zones = pts.buffer(0.5).union_all() # 0.5 m safety buffer around each detection
gpd.GeoDataFrame(geometry=[zones], crs=pts.crs).to_file("spray_zones.shp")
Case study
Case studies from my work: validating a crop row method with artificial datasets, and a repeatable feature-extraction pipeline.
References from my work
2025Q1
Aerial Image-Based Crop Row Detection and Weed Pressure Mapping Method
L. Moldvai, P. Á. Mesterházi, G. Teschner, A. Nyéki
Agronomy 2025, 15(8), 1762
Abstract
A six-phase, feature-based computer vision method that detects crop rows and generates weed pressure maps from UAV images taken at 20–30 m, without training data or deep learning. Tested on 208 images and 120 artificial datasets; the in-row concentration ratio (IRCR) tells whether a result is usable. With 678 crop plants and 600 weeds the method reached F1 = 86.32 %, and the weed-to-crop ratio correlated 98–99 % with ground truth.
Weed Detection and Classification with Computer Vision Using a Limited Image Dataset
L. Moldvai, P. Á. Mesterházi, G. Teschner, A. Nyéki
Applied Sciences 2024, 14(11), 4839
Abstract
How few training images are enough? Traditional feature-based computer vision (shape, distance-transform, colour-histogram and texture features) with six classifiers was tested on 5–160 images per weed type in a four-class problem. With 160 images per class a 94.56 % recall was reached, close to deep-learning accuracy with a tenth of the data.