# coccoexe/food-recognition-and-leftover-estimation architecture

> Architecture diagram of the GitHub repository coccoexe/food-recognition-and-leftover-estimation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coccoexe/food-recognition-and-leftover-estimation
- Repository: https://github.com/coccoexe/food-recognition-and-leftover-estimation

## Overview

##### Main Components
- Data Source:
- Core Image Processing Modules:
- Segmentation Component: Implemented mainly in src/Segmentation.cpp and src/Segmentation.hpp, where the segmentation algorithm processes top-view images.
- Metrics Calculation: In src/Metrics.cpp and src/Metrics.hpp, the consumption rate computations and comparisons between before/after images are performed.
- Main Application:
- Optional Interfaces/Extensions:
- Python Interface: Located in src/Python/CLIP_interface.py, potentially used for interfacing with other tools or providing a lightweight scripting interface.
- Legacy/Old Code: The old code directory shows previous experimental implementations (such as CLIP and image masking in C++ and Python). Although not the main execution path now, they might be mentioned for historical context or future reference.
- Documentation/Assignment Material:
- The assignment (in the assignment folder) and matching directories (likely experimental results) form a peripheral but essential documentation layer.

##### Relationships and Interactions
- Data Flow:
- The Segmentation Module outputs segmented regions (food parts, leftovers).
- The resulting data flows into the Metrics Module where the rate of food consumption is computed.
- The main application coordinates these operations.
- Interfaces:
- Dependencies:

##### Architectural Patterns and Design Principles
- Separation of Interface and Implementation: With the presence of both C++ and Python interfaces, the design separates low-level computation from higher-level interfacing.

##### Relevant Technologies
- C++: Core computation, segmentation, and metrics.
- Python: A scripting/bridging interface.
- Build/Configuration: CMake (CMakeLists.txt and CMakePresets.json) for project management.

- Adding configuration/build (CMake) as a supporting component that ties into the compilation and orchestration of the modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    DataSource["Food_leftover_dataset"]:::data
    MainApp["Main Application Coordinator"]:::cpp

    subgraph "Image Processing Pipeline (C++)"
        SegmentationModule["Segmentation Module"]:::cpp
        BoundingBoxHandler["Bounding Box Handler"]:::cpp
        MetricsCalculator["Metrics Calculator"]:::cpp
    end

    PythonInterface["Python Interface"]:::python
    Documentation["Documentation/Assignment Material"]:::doc
    Legacy["Legacy/Old Code"]:::legacy

    %% Connections
    DataSource -->|"provides_images"| SegmentationModule
    SegmentationModule -->|"outputs_segments"| BoundingBoxHandler
    BoundingBoxHandler -->|"processes_boxes"| MetricsCalculator

    MainApp -->|"orchestrates"| SegmentationModule
    MainApp -->|"orchestrates"| BoundingBoxHandler
    MainApp -->|"orchestrates"| MetricsCalculator

    PythonInterface ---|"interfaces_with"| SegmentationModule

    Documentation ---|"references"| MainApp
    Legacy ---|"contains_old_experiments"| PythonInterface

    %% Click Events
    click DataSource "https://github.com/coccoexe/food-recognition-and-leftover-estimation/tree/master/Food_leftover_dataset"
    click SegmentationModule "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/Segmentation.cpp"
    click SegmentationModule "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/Segmentation.hpp"
    click BoundingBoxHandler "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/BoundingBoxes.cpp"
    click BoundingBoxHandler "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/BoundingBoxes.hpp"
    click MetricsCalculator "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/Metrics.cpp"
    click MetricsCalculator "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/Metrics.hpp"
    click MainApp "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/main.cpp"
    click PythonInterface "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/src/Python/CLIP_interface.py"
    click Documentation "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/assignment/CV_22_23-Summer project.pdf"
    click Legacy "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/old code/CLIP_bread.py"
    click Legacy "https://github.com/coccoexe/food-recognition-and-leftover-estimation/blob/master/old code/old_Mask.cpp"

    %% Styles
    classDef cpp fill:#AED6F1,stroke:#154360,stroke-width:2px;
    classDef python fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef data fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef doc fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef legacy fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px;
```
