# ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits architecture

> Architecture diagram of the GitHub repository ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits
- Repository: https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits

## Overview

##### Main Components of the System
- Camera & Image Acquisition: The system uses a camera (e.g., Logitech C270) to stream real-time footage of fruits on the conveyor belt.
- Image Processing & Prediction Module: This includes the code that utilizes OpenCV and PIL to process images and the ML models (Xception in model/xception.py and possibly VGG16 from model/vgg16.py) to perform classification (fresh vs rotten).
- Data Management & Communication: Integration with Firebase for real-time updates of prediction results. Update operations for fruit counts and status are central to the system.
- Motor Control Module: Involves the Raspberry Pi integration and motor control code (files like motor/motor.py and motor/motor_control_db.py, along with motor-run.py) that act on Firebase updates to operate the DC-motor for separating rotten fruit.
- Graphical User Interface (GUI): The GUI (app.py and gui/main_gui.py along with gui/resources.py) displays real-time fruit counts from Firebase. It’s built using Qt Designer, indicating a clear separation of presentation from back-end processing.
- Training/Development Environment: The presence of train.py and a Jupyter notebook (in notebook/editing_dataset.ipynb) suggest environments to train the model and work with the dataset.
- Helper & Utility Code: helper.py likely contains various utility functions used across the processing.

##### Relationships and Interactions
- Data Flow: Begin with the Camera providing real-time images that move into an Image Processing module. After preprocessing, the images are classified via the ML model.
- Decision Making: Based on the classification outcome, the system updates the Firebase database with the current count of rotten vs. fresh fruits.
- Actuation: The Raspberry Pi monitors the Firebase database, triggering the motor control module to activate the motor if a rotten fruit is detected.
- User Interface: The GUI application polls or subscribes to Firebase updates to reflect the updated counts and statuses to the user.
- Training Pipeline: Separately, a training component (using train.py and the notebook) manages the machine learning model updates and validations, ensuring robust performance.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Divide the system into distinct modules (processing, database, motor control, GUI) to ensure each component can be maintained independently.
- Real-time Data Flow: Employ a streamlined data pipeline from image capture → processing → decision → motor actuation → user update.
- Integration with External Services: Emphasize dependency on Firebase for real-time data communication, and note the separate environmental requirements for Raspberry Pi.

##### Steps for Construction
- Drill down into each component showing internal modules (e.g., model files within ML engine, firebase_secrets requirement inside motor for secure database configuration).
- Every connection is clear: for instance, the motor module’s dependency on configuration from firebase_secrets, the GUI’s continuous data retrieval from Firebase, and so on.
- Asynchronous communications where relevant (e.g., real-time updates and continuous monitoring loops on Raspberry Pi).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Backend"
        A["Camera & Image Acquisition"]:::backend
        B["Image Processing & Prediction"]:::backend
        G["Helper & Utility Functions"]:::backend
        A -->|"processes"| B
        B -->|"pushes_results"| C(("Firebase Real-time DB")):::database
    end

    subgraph "Frontend"
        D["Graphical User Interface"]:::frontend
    end

    subgraph "Hardware / Control"
        E["Motor Control & Actuation"]:::hardware
    end

    subgraph "Training/Development"
        F["Training Environment"]:::training
    end

    C -->|"updates_UI"| D
    C -->|"triggers_motor"| E
    F -->|"model_update"| B

    click A "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/app.py / run.py"
    click B "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/model/xception.py"
    click B "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/model/vgg16.py"
    click D "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/gui/main_gui.py"
    click D "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/gui/resources.py"
    click D "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/app.py"
    click E "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/motor/motor.py"
    click E "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/motor/motor_control_db.py"
    click E "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/motor-run.py"
    click F "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/train.py"
    click F "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/notebook/editing_dataset.ipynb"
    click G "https://github.com/ierolsen/bachelor-thesis-project-ml-based-conveyor-belt-for-detecting-separating-rotten-fruits/blob/main/helper.py"

    classDef backend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef frontend fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef hardware fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef training fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef database fill:#D1C4E9,stroke:#6A1B9A,stroke-width:2px;
```
