Computer vision in precision agriculture

From orchard images to harvest insight.

A field-based study combining apple detection and ripeness classification. Follow the workflow from nighttime image capture and evolving annotation strategies to a YOLOv7 detector and a custom CNN classifier.

Amin Mavaddat · Fabio A. A. Andrade · Karl Thomas Hjelmervik
Erik Andrew Johannessen · Christian Hovden

YOLOv7 detecting apples on a tree with confidence boxes
82%Best detection F1
YOLOv7 · Sub-dataset 3Fig. 12 · paper
A field study in Gvarv, Telemark, Norway · 2021
82%Best apple detection F1
98.3%Custom CNN accuracy
0.120 sAverage detection time
74.8 MBYOLOv7 trained weights
01 / The field study

Built around images from a real orchard.

The image database was collected from Red Aroma apple trees in Gvarv, Telemark, Norway, across the 2021 growing season. The capture setup was designed to be simple and practical for orchard monitoring.

Nighttime photograph of apple trees in the orchardNight capture
Aerial view showing the orchard camera locationCamera location

A compact, on-site RGB setup

A Raspberry Pi HQ Camera with an Arducam 6 mm lens, manual focus, adjustable aperture, and LED illumination was positioned approximately five metres from the trees, at a height of two metres. Images were captured from two viewing angles during the day and at night. The night images were used because they provided better contrast and illumination.

May 14 – Sep 25Image-capture period
3,040 × 4,059 pxOriginal image dimensions
Raspberry Pi HQRGB camera system
5 m / 2 mDistance from tree / height

Move through the growing season

Explore the paper's time-based ripeness labels and capture period.

2021
May 14 · blossomJul 10Aug 15Sep 25 · capture ends
Image capture beginsBlossomingThe image-capture period starts on May 14 and continues through the growing season.
02 / Dataset design

Changing the labels changed the detector.

Rather than modifying the YOLO architectures, the study created three sub-datasets with different labeling, augmentation, and temporal-sampling strategies.

Diagram of the dataset and three sub-datasets used for detection and classification
Dataset structure from Fig. 5 in the paper
Interactive labeling explorer
Example apple image with Sub-dataset 1 annotations
Annotation strategy 01

Label almost all visible apples

In Sub-dataset 1, almost all visible apples were included in the labeling process.

241 tree images
Class 0Class 1Class 2

Class counts: 37 unripe · 168 semi-ripe · 36 ripe. Temporal sampling was used to maintain the 15% / 70% / 15% class distribution.

03 / Apple detection

The smallest sub-dataset produced the strongest F1 score.

YOLOv5, YOLOv7, and YOLOv8 were fine-tuned on each sub-dataset. The best reported detection result came from YOLOv7 trained with Sub-dataset 3.

YOLOv7 apple detection output with confidence scores
Example detection output · the paper's YOLOv7 result on an orchard image

Compare detector performance

Best F1 score (%) · select a training sub-dataset
YOLOv5YOLOv7YOLOv8
YOLOv5
72%
YOLOv7
77%
YOLOv8
70%
Sub-dataset 1Best result YOLOv7 · 77%
74.8 MBTrained weight size
120 msAverage per image

The reported 0.120 s average detection time was measured for a 3,040 × 4,056-pixel image. The paper also reports that performance was less satisfactory for heavily clustered apples and fruit occluded by leaves.

04 / Ripeness classification

From a detected apple to a harvest-time class.

Cropped apple images were classified into three temporal ripeness classes. The study compared fine-tuned CNNs, CNN feature extractors combined with ML classifiers, and a custom CNN.

Explore the three classes

Unripe

CLASS 0 / 03
Example of an unripe apple
UnripeSemi-ripeRipe
75–90 days remaining until harvestImage period: up to July 10

Classifier comparison

Accuracy (%) · results reported in the paper
Custom CNN
98.3
VGG16
92.4
VGG16 + XGB
92.3
VGG16 + RF
92.1

Dataset 2 contained 500 selected images, expanded to approximately 3,100 through augmentation. Results shown are the best achieved over 25 training cycles using 5-fold cross-validation.

05 / Generalization and limitations

Strong results, with visible edge cases.

The paper tested the detector on different apple varieties and background fruit, and separately evaluated the classifier on FruitNet. It also documents cases where detection remains difficult.

YOLOv7 detection examples on a different apple variety
Transfer to other views

Different varieties and backgrounds

The YOLOv7 detector was shown on different apple varieties and could detect background apples once they became recognizable, including examples that were not labeled during the training annotation process.

Apple tree image showing background apples and foliage
Detection limitation

Occlusion and dense clusters

The paper notes that detection was less satisfactory when apples appeared in highly clustered groups or were covered by leaves. These cases are important constraints for practical orchard deployment.

Classifier generality

A second evaluation on FruitNet

On the FruitNet dataset, the custom CNN achieved 96.2% accuracy. Fine-tuned ResNet-50 followed with 94.6%. This is a separate evaluation from the Dataset 2 cross-validation results shown above.

96.2%Custom CNN · FruitNet
94.6%ResNet-50 · FruitNet
Confusion matrix for the custom CNN classifier
Classification results

Custom CNN confusion matrix

The paper reports the confusion matrix for the custom CNN classifier alongside the classification accuracy comparisons.

The research paper

A Hybrid Deep Learning-Based Approach in Agricultural Sustainability: Apple Orchard Study

Amin Mavaddat, Fabio A. A. Andrade, Karl Thomas Hjelmervik, Erik Andrew Johannessen, and Christian Hovden.

Study location · Gvarv, Telemark, NorwayData collection · 2021Affiliation · University of South-Eastern Norway
Read full paper