Orchards and Vineyards: Counting Fruit and Bunches with Vision

Knowing how many fruit an orchard carries, or how many bunches a vineyard, several weeks before harvest changes the way a farm is run: thinning is adjusted, labour is planned, vats and cold rooms are sized, volumes are negotiated with buyers. For a long time this estimate relied on manual counts on a few trees or a few vines, with all the uncertainty of a small sample. In computer vision in agriculture, counting by vision promises to replace the sample with a pass over the whole plot. This article, the third use case in the series after the overview of the field, explains what is counted, why it is difficult, how to go from a number of visible fruit to a yield and what this demands of annotation. It continues with vision under cover, covered in the article on smart greenhouses, where the camera finds a more stable environment.

Why count by vision in orchards and vineyards: computer vision in agriculture serving yield

Yield estimation is one of the most sought-after services of computer vision in agriculture, because it conditions important economic decisions before harvest. It comes into play at several moments: at flowering, to adjust the load; at fruit set, to plan thinning; close to ripeness, to organise harvest and logistics. The traditional method relies on manual sampling. An operator counts fruit or bunches on a limited number of rows or vines, then extrapolates to the plot. This approach is slow, labour-intensive and sensitive to spatial variability: if the sampled vines are not representative, the extrapolation is wrong. Vision makes it possible to observe a far greater number of plants, repeatably, and to produce a map rather than an average. This promise nevertheless meets a basic difficulty: the camera sees only part of the fruit. The rest is hidden by foliage, by other fruit or by the structure of the plant. The whole challenge of a counting project in computer vision in agriculture lies in how the number of visible fruit is related to the number of real fruit.

What to count: flowers, fruit, bunches, berries

The first choice concerns the unit of counting. In orchards, flowers, young fruit or ripe fruit are counted, depending on the stage and the decision aimed at. In vineyards, inflorescences, bunches and sometimes berries are counted. Each unit raises its own difficulties. The flower is abundant and small, and its relationship with the final fruit is indirect, because a large share of flowers do not set. Young fruit is green against a green background, difficult to tell from foliage. Ripe fruit is coloured and contrasted, therefore easier to spot, but it comes late, when room for decisions is reduced. The bunch is an object of variable shape, whose size depends on the grape variety and the stage. The berry is the finest measure, essential for estimating weight, but it assumes a high resolution and a considerable number of objects. The choice therefore depends on the decision to be informed. An estimate of load at fruit set does not require the same thing as a harvest forecast a few weeks ahead. A project in computer vision in agriculture that starts by fixing the stage and the decision avoids collecting unusable images: a model trained on ripe fruit cannot count young green fruit.

The visual constraints of a computer vision in agriculture project in orchards and vineyards

Four constraints dominate. The first is occlusion. Foliage, branches, trellising and the fruit themselves hide a large share of the crop. A camera placed on one side of the row never sees all the bunches, and the hidden share varies with the variety, pruning, leaf removal and stage. The second is colour similarity. A young green fruit or a bunch of white grapes against green foliage offers very low contrast. Models then rely on shape, texture and context, and their errors are more frequent. The third is light. Direct sun creates reflections and hard shadows, an overcast sky flattens contrasts, backlighting destroys detail. One option is to photograph at night with on-board lighting, so as to impose constant light from one shot to the next. It removes the variability of the sun but adds a logistical constraint. The fourth is variability between plots, varieties and training systems. An orchard trained as a fruiting wall and an orchard of large trees do not present the same scenes, and a model trained on one generalises poorly to the other. This is a robustness subject covered in a dedicated article of the series.

Acquiring the images: from the ground, at night, by aircraft

Three acquisition modes share the field. The first is ground acquisition, from a tractor or a light vehicle that runs along the rows, with one or several side cameras. It is the most common mode for counting, because it gives the resolution needed to see fruit at a few millimetres per pixel and allows the camera to get close to the face of the row. The second is night acquisition with active lighting, which homogenises conditions and reduces shadows, at the price of heavier equipment and night-time organisation. The third is the unmanned aircraft, which flies over the plot. It covers large areas quickly, but sees mainly the top of the canopy, where fruit is often absent or hidden. It therefore suits vigour mapping better than fruit counting. A vineyard with rows spaced 2.5 metres apart represents about 4,000 metres of row per hectare. At 2 metres per second, a single pass on one side takes a little over half an hour per hectare, and two passes are generally needed to see both faces of each row. These figures, illustrative, give the order of magnitude of the acquisition effort, and justify the use of on-board equipment rather than manual shooting.

Double counting and tracking in a computer vision in agriculture project

A moving vehicle takes images that overlap. If a camera covers 1.5 metres of row and the machine advances at 2 metres per second at 10 frames per second, it moves 20 centimetres between two images. The same point of the row therefore appears in 7.5 consecutive images. Counting fruit image by image would multiply the result by a factor of about seven, which obviously has no agronomic meaning. Each object must therefore be tracked from one image to the next, so that it is counted only once. Tracking relies on position, appearance and the estimated motion of the camera. It fails when an object disappears behind a leaf and reappears, which creates false duplicates, or when two close objects merge, which creates false fusions. These errors are not corrected by a better detector, but by better tracking and consistent counting rules. For a project in computer vision in agriculture, the consequence for annotation is precise. Annotating isolated images makes it possible to train a detector, but not to measure the quality of counting. Sequences annotated with object identifiers are also needed, to assess whether the same fruit keeps the same identity from one image to the next and whether the total per row segment is exact.

From visible to total in a computer vision in agriculture project: the calibration factor

Even a perfect count of visible fruit does not give the total number, since part of it is hidden. Let us illustrate with numbers. Suppose the camera sees 60% of the bunches in a row, the rest being hidden, and that the model detects 92% of the visible bunches. It then counts 55.2% of the real bunches. To recover the total, one multiplies by a calibration factor of about 1.81. This factor is the weak point of the method, because the visible share is not constant. If, within a plot, it varies from 50% to 70% depending on leaf removal and vine vigour, a factor set at 60% overestimates the total by 20% where only 50% is visible, and underestimates it by 14% where 70% is visible. The error on the factor passes directly into the estimated yield. Teams reduce this risk in three ways. They set the factor on reference counts made by hand, on vines or trees chosen in several situations. They estimate it separately by block, variety or training system rather than globally. Finally, they measure the visible share directly, for example by manually counting all the fruit on a sample of trees before and after leaf removal. A project that neglects this step produces figures that look precise but are biased.

From image to yield: a worked example

The number of bunches is not the yield. An estimate of the average weight of a bunch is also needed, which depends on the variety, the season and the training system. Take an illustrative example: a vineyard of 4,000 vines per hectare carrying on average 12 bunches per vine, that is 48,000 bunches per hectare, with an average bunch of 120 grams. The expected yield is 5,760 kilograms per hectare. If the estimate has a mean error of 18%, the uncertainty corresponds to about 1,037 kilograms per hectare, an interval between roughly 4,700 and 6,800 kilograms. This range is enough to plan vats, but not to set a selling price per tonne. The usefulness of a system therefore depends on the precision that the decision requires, and teams do well to fix it before developing. The error on bunch weight adds to that of counting. It comes from natural variability, from berry size, which changes with the weather of the last weeks, and from a possibly insufficient measurement of the reference sample. A good project tracks the counting error and the weight error separately, to know which one to improve.

What a large-scale study shows about computer vision in agriculture in vineyards

A study circulated in 2022 by Olenskyj and colleagues illustrates these stakes at large scale. The authors equipped a vehicle with a capture kit in a mechanically managed commercial vineyard in California Central Valley. Their dataset comprises 107,933 images and 23,581 yield points, paired with the measurement of a commercial yield monitor at harvest. They compared three approaches: object detection, regression with a convolutional network and a transformer-type model. The most instructive result is twofold. On the one hand, the mean absolute percentage error stays around 18%, 18% for the transformer and 18.5% for object detection with pixel-area processing, on a representative held-out set. Such a level is consistent with the order of magnitude of the previous example. On the other hand, regression approaches, which estimate yield directly from the image without manual annotation of each object, reach performances comparable to detection. They shift the need for annotation: boxes are no longer drawn around bunches, but a reliable, geolocated yield ground truth aligned with the images must be available. This observation does not abolish annotation. A detection approach remains more explainable, allows counting to be checked visually and helps diagnose errors; direct regression is more economical in annotation but harder to audit. The choice depends on what the team wants to be able to explain to the grower.

Annotating fruit and bunches in a computer vision in agriculture project

Annotating for counting raises questions of rule more than of drawing. The first is the visibility threshold: is a fruit visible at 20% annotated? At 50%? The answer changes the number of objects, hence the calibration factor. A common rule is to annotate every object of which at least a given proportion is visible, and to mark the others as partly occluded, so that the threshold can be changed without redoing the annotation. The second is the separation of close objects. Two adjoining bunches count as two, but where does the boundary lie when they touch? The guidelines must specify the criterion, for example two distinct peduncles, and illustrate borderline cases with commented examples. The third is the annotation form: a box is enough to count, a mask becomes useful to estimate size, and a centre point is sometimes enough for very small, numerous objects such as berries. The fourth concerns ambiguous, blurred or overexposed images. Discarding them under a clear rule is better than letting each annotator decide in their own way. Agronomic supervision completes the setup: an annotator with no reference points on the morphology of the variety or the fruit confuses a bunch with a cluster of leaves more easily. In a quality project in computer vision in agriculture, a pilot batch, annotated by several people and then compared, serves to calibrate the guidelines before production. Quality control for counting annotation works differently from quality control for boxes. A box can be checked by overlap; a count must be checked by an independent recount of a sample of images, and discrepancies of even one object per image are informative. In computer vision in agriculture, teams therefore reserve a share of images for double annotation, for example 10% in a pilot, and compare the totals per image before comparing the geometry. A systematic gap between two annotators on the same images usually points to a guideline that two people read differently.

Calendar: stages and counting windows

The season imposes a tight calendar. Counts are made at precise stages, sometimes within a window of a few days. Missing the window means waiting for the following year, and a dataset that covers only one stage will serve only for that stage. A project in computer vision in agriculture must therefore plan collection around the crop cycle, reserving the critical windows and allowing a margin for weather. Annotation planning follows the same rhythm. Images collected in spring must be annotated early enough to train and evaluate a model before the next season, or to serve an in-season estimate. Teams that discover their guideline errors after the last collection window can no longer correct them on new images. A useful practice is to spread shooting over several stages from the first season, even with few images per stage, so as to detect differences in model behaviour between stages. This avoids believing that a good score at one stage holds for the whole season. Each image should also carry a stage label and a date, whether the stage comes from a grower observation or from a scale of phenological development. Without it, a model that performs well on images from one week may be credited with a skill it only has at that stage, and the first image from a later stage will contradict it. Stage labels are cheap to record at the time of shooting and almost impossible to reconstruct afterwards.

Measuring counting error

The reference indicator is counting error per unit of area: row, block or plot. Bias, which indicates systematic underestimation or overestimation, must be distinguished from dispersion, which measures noise. Take an illustrative example on five row segments whose real counts are 118, 95, 142, 87 and 130 bunches, 572 in total, and for which the system counts 101, 90, 109, 80 and 118 respectively, 498 in total. The mean percentage error is 12.0%, and the overall bias minus 12.9%: the system underestimates systematically, which is consistent with the hidden share. Applying a single calibration factor of 1.15 brings the mean error down to 6.4%, because most of the error was bias. But the example is calibrated on the same segments it evaluates, which is too favourable: the factor must be determined on blocks other than those used for evaluation. In a project in computer vision in agriculture, the distinction between bias and noise guides the work. A bias is corrected by calibration; high noise calls for more data, better guidelines or better tracking. A single indicator confuses them, and teams that look only at the average lose the means to know where to act.

The role of an annotation provider

Counting, separation, visibility thresholds and sequences with identifiers: in a project in computer vision in agriculture, these tasks demand trained annotators and stable guidelines. A specialised provider brings this discipline, and frees agtech teams for the modelling and calibration work. Infoscribe AI works on this type of project with fully manual annotation, structured quality control, a tool hosted on its own infrastructure and an ISO 27001:2022 certified approach. Its annotation service for agriculture processes images taken at ground level or from aircraft, as well as sequences, according to guidelines developed with the client. A pilot on a sample of your own images makes it possible to check throughput and quality before any commitment.

Common mistakes in counting fruit and bunches

  • Counting image by image, without tracking, and multiplying the result by the number of overlaps.
  • Ignoring the share of hidden fruit, and presenting the visible number as a yield.
  • Setting a single calibration factor for very different plots and training systems.
  • Evaluating the factor on the same blocks as those used to determine it.
  • Not fixing the visibility threshold before annotating, then changing it along the way.
  • Collecting at a single stage and assuming that the model holds for the whole season.
  • Summarising performance with a single mean error, without separating bias and dispersion.
  • Forgetting the error on average weight, which adds to that of counting.
  • Using images taken in the wrong season to train a young-fruit model.
  • Neglecting the yield ground truth, indispensable for regression approaches.

Key takeaways

Counting fruit and bunches is one of the most profitable uses of computer vision in agriculture, because it informs economic decisions before harvest. It meets occlusion, colour similarity, light and the variability of plots. Three ideas structure a project. Tracking avoids double counting: with 7.5 images per point of the row in the example, counting without tracking would be wrong by a factor of seven. Calibration relates visible to total: with 60% of bunches visible and 92% detection, the factor is 1.81, and a visible share varying from 50% to 70% makes it vary from plus 20% to minus 14%. Evaluation distinguishes bias from noise and is done on blocks distinct from those of calibration. The study by Olenskyj and colleagues is a reminder that at large scale an error of about 18% remains a respectable result, and that regression approaches shift the annotation effort rather than remove it. For the rest of the series, one can continue with smart greenhouses, or return to the overview of the field. To scope an annotation pilot on a sample of your own row images and obtain an estimate of throughput and quality, describe your project to the team. References: Olenskyj et al., End-to-end deep learning for directly estimating grape yield from ground-based imagery, arXiv 2208.02394. The numerical examples on the calibration factor, yield, image overlap and counting error are illustrative.
Tags

Découvrez nos articles