Computer Vision in Agriculture: Precision Farming with AI
Using drone imagery and an object detector to flag crop that is ready to harvest sounds simple. The model is the small part. Labelling, image tiling, changing light and what counts as a mistake decide whether it is useful.
The pitch for computer vision in farming is easy to say: fly a drone over a field, run a model on the photos, and get a map of which parts are ready to harvest. The first working version of that really is quick to build with a modern detector such as YOLOv8. The distance between that first version and something a farmer would rely on is almost entirely about data and definitions, and that is where this article spends its time.
Decide what you are detecting before you collect anything
"Ready to harvest" is not a visual category until someone defines it. Colour, size, firmness and days since flowering all play a part, and two experienced growers may disagree about borderline plants. Sit down with an agronomist or the grower and write a short labelling guide with example photos for each class: not ready, nearly ready, ready, and overripe if that matters for the crop.
Then label a small batch with two people and compare. Where they disagree, the guide is unclear, not the people. It is much cheaper to settle this on two hundred images than on five thousand.
Drone images are the wrong shape for most detectors
A drone photo might be twelve megapixels or more, while a detector like YOLOv8 is usually trained and run at something like 640 or 960 pixels on the long side. Shrink the full frame down to that and a single fruit or flower head becomes a few pixels wide. The usual fix is tiling: cut each image into overlapping squares, run the detector on each tile, and merge the results, removing duplicate boxes where tiles overlap.
Flight height matters for the same reason. The lower you fly, the more pixels land on each plant, at the cost of covering less ground per battery. It is worth flying one test field at two or three heights and checking what the model can actually see before you plan a season of flights.
Training is the quick part
With labelled images exported in YOLO format, a first training run is a single command.
yolo detect train data=crop.yaml model=yolov8s.pt imgsz=960 epochs=100 batch=16
Start with a small model and see how far it gets. A larger model rarely fixes a problem that is really about the labels or about images that look different from your training set.
The model that works in one field fails in the next
This is the problem that surprises people. A model trained on photos from one field, in the morning, in sunlight, will often lose accuracy on another field, in cloud, or a week later when the foliage has changed. The model learned your conditions as much as it learned the crop.
Handle it in the data. Collect images across different times of day, weather and growth stages. When you evaluate, hold out whole fields or whole flights rather than random images, because random splits put near-identical neighbouring photos in both training and test sets and make the score look better than it is.
Pick the metric that matches the cost of a mistake
An overall accuracy figure hides what a grower cares about. Missing a ready patch (a false negative) means crop left too long. Flagging a patch that is not ready (a false positive) means a wasted trip. These cost different amounts, and the balance depends on the crop and the harvest window.
Look at precision and recall for the "ready" class on its own, and adjust the confidence threshold to suit. For many growers an extra false alarm is acceptable, and a missed field is not.
Turn detections into something a person can act on
A pile of boxes on photographs is not a deliverable. What helps is a map: each detection tied to a position using the drone's GPS data, grouped into zones, and shaded by how much of that zone is ready. Photos from drones usually carry location tags, and stitching tools can produce an orthomosaic that you can overlay on a base map.
Keep the zones coarse enough to be useful on foot or on a tractor. A map with ten thousand tiny dots makes people trust it less.
Where does the model run?
The simplest option is processing after the flight on a laptop or a cloud machine, then sending a report. That is fine when the harvest decision can wait a few hours. Running on the drone or on a small device in the field is possible, but it adds engineering and limits the model size, so only do it if a real-time result changes what someone does.
What it will not do
- See through leaves. Fruit hidden under canopy will be missed, and the model's counts will be lower than the truth. Calibrate against hand counts on sample plots.
- Replace walking the field. It is a way to decide where to look first.
- Stay accurate forever. New varieties, a different camera or a change in planting layout all mean retraining or at least rechecking.
The projects that work treat the first season as data collection. Fly regularly, keep labelling a small amount each time, and check the model against what the grower actually found. By the second season you have a dataset that matches your fields, and that is worth more than any choice of model.