After picking, a fruit changes setting but not logic: it still has to be decided, in a fraction of a second, whether it is compliant, which grade it belongs to and in which size category it will be sold. It is in packing stations that computer vision in agriculture looks most like industrial machine vision, with conveyors, controlled lighting and high throughput. Yet the object remains alive: two apples of the same variety never show the same skin, the same marks or the same colour.
This article, the second in the series after the overview of the field, deals with sorting and grading. It describes the line, the sensors, the definition of defects, the trade-off between false rejects and missed defects, and the demands these choices place on annotation. It continues with vision in orchards and vineyards, presented in the article on counting fruit and bunches.
From orchard to packing: computer vision in agriculture after harvest
Post-harvest sorting is one of the oldest uses of vision in agriculture, because it combines favourable conditions: a controlled scene, objects presented one by one, chosen lighting and a binary decision or a few classes. A project in computer vision in agriculture finds more stable ground here than in the field, but ground that is demanding on throughput and accuracy, because every error is paid for immediately in produce wrongly discarded or in a downgraded lot. The economic stakes are direct. A badly classified fruit is either a loss, if it is discarded when it was sellable, or a claim, if it is shipped with a defect. Vision must therefore replace a human visual sort, slow and variable from one person to another and from one hour to the next, with a consistent and traceable decision. It does not always remove human control at the end of the line, but it directs that control towards doubtful cases. A systematic review published in 2025 in the journal Sensors analysed 56 articles published between 2015 and 2024 on vision systems for fruit inspection and classification. It notes that colour cameras account for 84% of the applications recorded, far ahead of hyperspectral at 5%, and that most studies were carried out in the laboratory, which limits validation under real conditions. It also points out that 74% of the studies rely on proprietary data, for lack of specialised public datasets. These findings set the frame for this article: the basic technique is accessible, and the difficulty is concentrated in the data and in their validity outside the laboratory.What is sorted and what is graded
Grading divides products by size: diameter, weight or estimated volume. Sorting divides them by quality: colour, shape, surface condition, defects, apparent ripeness. The two are often done on the same line, with the same cameras, but follow distinct criteria and do not pose the same problems for annotation. For size, vision measures a dimension from the silhouette and converts it into millimetres through calibration. Annotation here is mainly geometric: the outline of the fruit, sometimes landmark points. For quality, the decision depends on a catalogue of defects: bruises, scars, spots, russeting, rots, splits, insects, hail marks, sunburn. Each defect has its shape, its size, its severity, and the decision to reject often depends on the area affected. Criteria vary with the outlet. A fruit intended for the fresh market is judged on its appearance and firmness. A fruit intended for processing tolerates more marks but requires the absence of rot. An exported fruit meets a buyer specification, sometimes stricter than the commercial standard. The same vision model therefore does not serve everywhere without adjustment, and the training set must reflect the targeted outlet.A sorting line seen by a computer vision in agriculture project
A sorting line begins with singulation. Fruit leaves a bin, passes on a belt or on rollers, and is separated from its neighbours, because vision can only judge one fruit at a time. Rotating rollers turn each fruit as it advances, so that cameras see several sides. A zone of controlled lighting, often under a shroud, evens out the light. Cameras placed above and on the sides take several views. A computer combines the views, assigns the fruit a size and a category, and commands the ejector or gate at the exit that will direct it to the right bin. For the computer vision in agriculture project that equips such a line, the work plays out at three levels. At sensor level: choosing resolution, frame rate and lighting. At algorithm level: detecting the fruit, describing it, detecting defects, aggregating views. At system level: keeping up with throughput, synchronising the decision with the flow, managing settings by variety and by lot. The major difficulty comes from combining views. A defect visible on one side only can be missed if that side is not turned towards a camera, and the same defect seen twice must not be counted twice. The aggregation rule, for example reject if at least one view shows a serious defect, is part of the decision in the same way as the model.The sensors of a post-harvest computer vision in agriculture project
The colour camera is the basis, for a simple reason: most commercial criteria are visual. It measures ground colour and surface colour, and spots marks, spots and deformations. With good lighting and suitable optics, it is enough for a large share of external defects. The near-infrared or multispectral camera reveals what colour masks: a recent bruise, still invisible to the eye, absorbs light differently from healthy flesh. It makes it possible to spot defects that would only appear on the shelf, after a few days. The hyperspectral camera goes further, with dozens of bands, but its cost, its data volume and its complexity of use reserve it for specific cases, such as estimating sugar content or detecting internal defects. Other sensors complement vision for internal defects: X-rays for stones, cavities or insects in the flesh, spectroscopy for sugar, acidity or firmness, acoustic or vibration measurement for texture. They fall outside vision proper, but their measurements are often added to those of the camera in the final decision. The choice depends on the value of the defect sought. A colour camera is enough to sort apples for the fresh market; looking for an internal cavity in a high-value fruit may justify much heavier equipment. The question to ask is always the same: which defect loses money, and which sensor sees it.Lighting and staging the fruit
Image quality depends first on lighting. A shiny fruit returns reflections, which mask defects or imitate them. A spherical fruit is lighter at the centre than at the edges, which distorts colour measurement. Sorting lines use diffusing domes, polarisers, LED lighting with a controlled spectrum and uniform backgrounds to neutralise these effects. Staging the fruit matters just as much. Rotation speed, spacing, stem position and shooting height change what the camera sees. A project that changes variety or size without revisiting these settings obtains images different from those of training, and a model that had proved reliable becomes hesitant. For annotation, this control is an advantage. Images from a sorting line are more homogeneous than those from a field, which makes it easier to write guidelines and to measure agreement between annotators. In return it demands that the acquisition configuration of each batch be documented precisely, because a change of lighting is enough to make two batches incomparable. A short daily routine keeps such a system honest. Each morning, a small set of reference fruit with known classes, say twenty pieces including a few borderline marks, is run through the line, and the decisions are compared with the expected ones. A deviation points to a dirty lens, a failing lamp or a shifted camera long before the lot statistics reveal it. The reference set is also the natural seed for the pilot batch of any new annotation campaign, since its labels have already been agreed by the quality manager.External defects and how they are defined
In a computer vision in agriculture project, the definition of defects is the point at which annotation decides the quality of the model. A defect has no universal definition: it is defined in relation to a commercial standard, a specification or a reference sample. The marketing standard for apples, in the version published by the United Kingdom government, distinguishes three classes, Extra, I and II, and sets numerical tolerances: for Class I, elongated skin defects up to 2 centimetres in length, other defects up to 1 square centimetre, and slight bruising not exceeding 1 square centimetre; for Class II, 4 centimetres, 2.5 square centimetres and 1.5 square centimetres. It also sets a minimum size of 60 millimetres in diameter or 90 grams. Such thresholds have a direct consequence for annotation: an area has to be measured. A defect of 1 square centimetre, or 100 square millimetres, occupies 400 pixels if one pixel represents 0.5 millimetre, 100 pixels if one pixel represents 1 millimetre and 25 pixels at 2 millimetres. The precision of the outline then becomes decisive. For a circular defect of 1 square centimetre, whose radius is about 5.6 millimetres, an outline error of one pixel on the radius changes the area by minus 32% to plus 39% at 1 millimetre per pixel, and by minus 17% to plus 18% at 0.5 millimetre per pixel. In other words, deciding whether a mark exceeds the Class I threshold calls for an image resolution and an outline rigour that simply spotting a defect does not require. The guidelines must therefore specify, for each type of defect, the annotation form, box, polygon or mask, the rule for separating two neighbouring defects, how to handle a partly visible defect, and the severity threshold if it can be assessed visually. They benefit from being accompanied by a library of reference fruit, photographed and classified by the quality manager of the station.Internal defects and ripeness
Not every criterion can be read on the skin. Ripeness, firmness, sugar content, the presence of a brown core or a cavity call for other sensors. In computer vision in agriculture, a colour camera nevertheless gives useful clues: ground colour is correlated with the ripeness stage for several species, and some internal alterations show on the surface with a delay. The trap is to ask annotation for what it cannot provide. If the label of a fruit as ripe or unripe comes from a laboratory measurement, for example a sugar assay, it is that measurement that counts, and the annotator does not have to guess it from the image. The training set then associates the image with a value measured by other means, and the visual annotation work is limited to what a person can reasonably see. Mixing these two sources without distinguishing them produces labels that nobody can check.Throughput and time budget in a computer vision in agriculture project
A modern station sorts at high rates, which constrains every stage of the system. Take an illustrative example: a line that processes 12 tonnes of apples per hour, with fruit of 180 grams, sorts about 66,700 fruit per hour, or 18.5 per second. Spread over four lanes, the rate is 4.6 fruit per second per lane, which leaves about 216 milliseconds per fruit to do everything: acquisition, computing, decision. If each fruit is seen from four angles, the system processes 74 images per second across the whole line. The time budget conditions the choice of model. A very accurate but slow network does not fit in 216 milliseconds, and the accuracy lost by simplifying the model must be measured on the most costly defects. This is a trade-off that a computer vision in agriculture project negotiates constantly: stay light enough to keep up with throughput, fine enough not to miss the defects that matter. Throughput also affects collection. A line running eight hours a day produces hundreds of thousands of images, the vast majority showing compliant fruit. It is impossible, and pointless, to annotate them all. Sampling must favour images of defects, borderline cases and under-represented varieties, as for any imbalanced dataset.False rejects and missed defects in a computer vision in agriculture project
A sorting system makes two types of error, and their costs differ. Take an illustrative lot of 1,000,000 fruit, of which 3% carry a defect, that is 30,000 defective fruit. A system that detects 94% of defects and rightly accepts 98% of sound fruit lets through 1,800 defective fruit and wrongly discards 19,400. Among all rejected fruit, 47,600 in total, only about 59% are really defective. If the threshold is set to miss only 900 defects, with a recall of 97%, specificity falls to 96% in the example, and false rejects rise to 38,800: the share of justified rejections drops to 43%. If specificity is favoured instead at 99%, with a recall of 90%, missed defects rise to 3,000 and false rejects fall to 9,700, for 74% of justified rejections. No setting is universally good: the choice depends on the cost of a defect delivered, which may be a claim or a loss of trust, and on the cost of a false reject, which is often a downgrade to a less valued category. This reasoning dictates how the model is measured. A single accuracy percentage hides these trade-offs, all the more so because 97% of fruit being compliant makes overall accuracy misleading. Experienced teams track recall by defect type, specificity and the share of justified rejections, on a lot representative of real production, and not on the training set.Commercial standards and annotation guidelines in a computer vision in agriculture project
Commercial standards serve as the foundation for guidelines, but do not replace them. A standard states tolerances in regulatory language: area, length, number. An annotation guideline must transpose them into observable gestures: which shape to draw, which defect to separate from which other, what to do when a mark straddles two sides of the same fruit. In a computer vision in agriculture project, this transposition is done with the quality manager of the station, who knows the practical interpretation of the standard and the particular requirements of customers. It is documented, versioned and tested on a pilot batch, where several annotators label the same fruit to measure their agreement. Disagreements reveal the ambiguous passages of the guideline, which are clarified before production starts. A buyer specification often adds criteria of its own, for example a minimum colour or a shape tolerance. These requirements vary from one customer to another, and the dataset must be able to be re-annotated without starting from scratch if criteria change. Designing rich labels from the outset, which keep the shape and size of the defect rather than a simple reject decision, makes this evolution possible.Building and maintaining the dataset
The training set of a computer vision in agriculture sorting project must cover varieties, sizes, harvest seasons, storage durations and conservation conditions. A fruit taken out of cold storage in March does not show the same marks as a fruit from the October harvest, and the same variety changes appearance depending on its region of origin. The rarity of defects calls for deliberate sampling. On a line where 3% of the fruit is defective, collecting 100,000 images at random yields on average 3,000 images of defects, but very unevenly spread between types: frequent defects will be well represented, rare ones almost absent. The set must therefore be completed by targeted campaigns, deliberately pulling the fruit that carries the rare defects. Maintenance of a computer vision in agriculture project is just as important. A new variety, a new supplier, a change of lighting or camera, a revised specification all require the model to be re-evaluated and often the set to be completed. Stations that provide a loop for reporting errors, with periodic review of misclassified fruit, enrich their set as they go and avoid silent drifts.The role of an annotation provider
In a computer vision in agriculture project, the definition of defects and the rigour of outlines, two decisive points for sorting, call for trained annotators and a quality control that measures agreement. Many stations and equipment makers choose to entrust this phase to a provider, so as to concentrate their engineers on the system. 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 covers the annotation of fruit and vegetables, with boxes, polygons and masks, 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 sorting and grading
- Defining defects by adjectives rather than measurable criteria.
- Using an image resolution too low to measure the area of a defect at the threshold of the standard.
- Annotating with an outline precision that does not allow a decision between two classes.
- Evaluating the model on a single overall accuracy, when 97% of fruit is compliant.
- Setting the rejection threshold without knowing the cost of a false reject and that of a defect delivered.
- Forgetting the aggregation rule between the views of the same fruit.
- Training on one variety or one season, then deploying on others without re-evaluation.
- Changing lighting or rotation speed without recording the change in the metadata.
- Asking visual annotation to guess a laboratory measurement.
- Not planning a targeted campaign for rare defects.