Real-time orange detection and counting on a conveyor belt using a fine-tuned YOLO11 model with Ultralytics ObjectCounter.
Each orange is detected, tracked, and counted as it crosses a counting line β giving a live count overlay on the video.
This project follows a complete ML pipeline, from data collection to deployment:
- Frame extraction β Extract frames from the conveyor belt video.
- Auto-annotation with Grounding DINO β Use Grounding DINO (zero-shot object detection) to automatically generate bounding box annotations from a text prompt, eliminating the need for manual labeling from scratch.
- Annotation refinement in CVAT β Import auto-generated annotations into CVAT and manually correct errors (split grouped detections, remove false positives, add missed oranges).
- Fine-tune YOLO11 β Train a YOLO11n model on the corrected dataset using Google Colab (T4 GPU).
- Counting & tracking β Use Ultralytics ObjectCounter with a user-defined counting line to track and count oranges in real-time.
The fine-tuned model achieves good performance on the validation set:
| Metric | Value |
|---|---|
| mAP50 | 98.70% |
| mAP50-95 | 85.09% |
| Precision | 95.99% |
| Recall | 94.88% |
# Clone the repo
git clone https://github.com/IIIllllIlIlllII/orange-counter-conveyor-belt.git
cd orange-counter-conveyor-belt
# Python 3.8+ required (recommended: 3.10 or 3.11)
pip install -r requirements.txtThe trained model weights (best.pt) are included in the repository. You can also train your own using the provided notebook.
# Interactive β click 2 points to place the counting line
python orange_counter.py --source your_video.mp4 --model best.pt --interactive --save
# With predefined line coordinates
python orange_counter.py --source your_video.mp4 --model best.pt --points 0,613,1077,1076 --save
# Adjust confidence threshold
python orange_counter.py --source your_video.mp4 --model best.pt --points 0,613,1077,1076 --conf 0.5 --save| Argument | Default | Description |
|---|---|---|
--source |
orange_video.mp4 |
Path to input video |
--model |
best.pt |
YOLO model weights |
--points |
Line coordinates: x1,y1,x2,y2 |
|
--interactive |
Click 2 points on the first frame to place the line | |
--conf |
0.6 |
Detection confidence threshold |
--output |
output.avi |
Output video path (used with --save) |
--save |
Save the annotated output video | |
--no-show |
Don't display the video window |
The notebook train_from_cvat.ipynb contains the full training pipeline for Google Colab. It covers uploading your corrected CVAT annotations, splitting the dataset, training YOLO11, evaluating performance, and downloading the trained weights.
To create your own dataset:
- Extract frames from your video
- Use Grounding DINO to auto-annotate
- Import into CVAT, correct the annotations, and export in YOLO 1.1 format
- Upload to Colab and run
train_from_cvat.ipynb
Export the model for optimized inference on edge devices or industrial PCs:
# ONNX (portable β runs on any platform)
yolo export model=best.pt format=onnx half=True
# TensorRT (optimized for NVIDIA GPUs)
yolo export model=best.pt format=engine half=TrueThen use the exported model directly:
python orange_counter.py --source your_video.mp4 --model best.onnx --interactive --save
python orange_counter.py --source your_video.mp4 --model best.engine --interactive --saveorange-counter-conveyor-belt/
βββ orange_counter.py # Main detection & counting script
βββ train_from_cvat.ipynb # Training notebook (Google Colab)
βββ requirements.txt
βββ .gitignore
βββ LICENSE
βββ README.md
βββ assets/
βββ demo.gif # Demo video
βββ training_curves.png # Training loss & metrics
βββ predictions.png # Sample predictions
- Ultralytics YOLO11 β Object detection, tracking & counting
- Grounding DINO β Zero-shot auto-annotation
- CVAT β Annotation refinement
- OpenCV β Video I/O & display
- Google Colab β Model training (T4 GPU)
MIT


