A real-time computer vision system for counting chocolates and bottles on conveyor belts using YOLO object detection and tracking.
- Overview
- Features
- Project Structure
- Requirements
- Installation
- Usage
- Model Training
- Configuration
- Results
- Troubleshooting
This project implements an automated counting system for factory conveyor belt. Using YOLO11 object detection and tracking, currently the system counts chocolates and bottles as they cross a user-defined line in real-time.in future carious other classes will be added .Trained model is not added in this repo . One can use their own trained model change the model paths in pharms.yaml file .
- Real-time counting: Track and count objects crossing a defined line
- Bi-directional tracking: Separate counts for IN and OUT directions
- Multi-class detection: Chocolates and bottles
- Multi-camera support: Process multiple camera feeds simultaneously
- Visual feedback: Neon-style bounding boxes with color-coded states
- MLflow integration: Track training experiments and model versions
- π― Accurate Detection: YOLO11 model trained on factory conveyor data
- π Class-specific Counting: Tracks counts per object type (chocolate, bottle)
- π¨ Neon Visual Effects: Modern corner-box visualization with glow effects
- π₯ Flexible Input: Support for video files, RTSP streams, and webcams
- π Experiment Tracking: MLflow integration for model versioning
- π Persistent Tracking: Object IDs maintained across frames
- β‘ Real-time Processing: Efficient multi-threaded architecture
factory_chocolat_counting/
β
βββ src/
β βββ data_ingestion.py # Download datasets from Roboflow
β βββ model_building.py # Train YOLO model with MLflow
β βββ postprocessing_bisunesslogic.py # Single-camera counting
β βββ postprocessing_bisunesslogic_multicameraprocessing.py # Multi-camera counting
β
βββ parms.yaml # Training configuration
βββ requriments.txt # Python dependencies
- Python 3.8.11
- CUDA-capable GPU (recommended)
- Clone the repository
git clone [repository_url]
cd factory_chocolat_counting- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
# install from requirements file
pip install -r requriments.txtFor single webcam, RTSP stream, or video file:
python src/postprocessing_bisunesslogic.pyInteractive setup:
- Choose input source (video file or camera)
- Select counting line: Click 2 points to define the line
- Watch real-time counting with visual feedback
Controls:
q: QuitENTER: Confirm line selectionESC: Exit during line selection
For multiple simultaneous camera feeds:
python src/postprocessing_bisunesslogic_multicameraprocessing.pySetup:
- Enter camera indices (e.g.,
0 1for two cameras) - Draw counting line for each camera
- System processes all feeds in parallel
The system uses line-crossing detection:
- Red bounding box: Object detected, not crossed yet
- Yellow flash: Object just crossed the line (4 frames)
- Green bounding box: Object already counted
- Counts displayed:
[CLASS_NAME] IN: X OUT: Y
Line-crossing algorithm: Detects which side of the line an object's center point is on and tracks direction changes.
- Configure parameters in
parms.yaml, please modify the parameters according to your project setup:
model_path: yolo11n.pt
data_yaml_path:Project-3/data.yaml
epochs: 100
batch: 4
imgsz: 640
device: 0 # GPU device
experiment_name: "choclate_identification_yolo_11"
mlflow_tracking_uri: "http://12.0.0.1:9000"- Set up MLflow tracking server:
mlflow server - Run training:
python src/model_building.pyTrained models are automatically logged to MLflow with metrics and artifacts.
- View results in MLflow UI:
# MLflow UI should be accessible at http://localhost:5000
# View experiments, compare runs, and download modelsmodel_path: Pre-trained YOLO model (e.g.,yolo11n.pt)data_yaml_path: Dataset configuration fileepochs: Number of training epochs (default: 100)batch: Batch size (default: 4)imgsz: Image size (default: 640)device: GPU/CPU device (0for GPU,cpufor CPU)experiment_name: MLflow experiment namemlflow_tracking_uri: MLflow server URL
- Confidence threshold: 0.7 (hardcoded)
- Classes: [0, 1] (chocolate=0, bottle=1)
- Tracking: Persistent tracking enabled (
persist=True) - Flash duration: 4 frames after crossing
- Classes: Chocolate, Bottle
- Dataset v3: 780 train / 75 valid / 37 test images
- Dataset v2: 570 train / 55 valid / 27 test images
- Best Model:
runs/detect/train5/weights/best.pt - Format: YOLO8/OBB format
- Bi-directional counting: Accurate IN/OUT detection using line-crossing algorithm
- Multi-threaded: Efficient processing of multiple camera feeds
- Visual feedback: Real-time neon-style corner boxes
- Frame persistence: Objects tracked across frames with unique IDs
- Per-class tracking: Separate counts for each object type
The system displays:
- Neon corner boxes: Modern corner-only visualization with glow effects
- Center tracking: Cyan circle at object center
- Class labels: Object type and confidence score
- Counting line: Red line showing detection boundary
- Count displays: Real-time IN/OUT counts per class
Color coding:
- π΄ Red: Newly detected object
- π‘ Yellow: Just crossed (flash effect)
- π’ Green: Already counted
- Classes: 2 (bottle, chocolate)
- Total images: 892
- Format: YOLO11
- Source: Roboflow factory conveyor belt footage
datasets validated with matching image/label pairs. The dataset can be accessed via this url : https://universe.roboflow.com/monitorshrimps/industrial_dataset-xzhwj
See LICENSE file for details.
Issue: Camera not opening
- Check camera permissions
- Verify camera index is correct
- Try different indices (0, 1, 2...)
Issue: Model not found
- Verify
best.ptexists inruns/detect/train5/weights/ - Update path in scripts if moved
Issue: Poor detection accuracy
- Adjust confidence threshold in scripts
- Retrain with more epochs
- Use more diverse training data
Issue: Multi-camera setup fails
- Ensure camera indices are correct
- Check if cameras are already in use
- Verify sufficient USB bandwidth
Built with using Ultralytics YOLO, OpenCV, and MLflow