# chando0185/car_parking_detection_space_count architecture

> Architecture diagram of the GitHub repository chando0185/car_parking_detection_space_count, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chando0185/car_parking_detection_space_count
- Repository: https://github.com/chando0185/car_parking_detection_space_count

## Overview

##### Project Type and Purpose
- This is a full-stack web application for real-time parking space detection. It has two main phases:
a. Model training/data preparation (offline)
b. Inference & web-serving (online)

##### Main Components
A. Training Pipeline (offline)
- Data Collection Script (datacollection.py)
- Jupyter Notebook (“Car Parking System Using Deep Learning.ipynb”)
- Training Data Archive (train_data.zip)
- Training Framework (TensorFlow/Keras)
- Output Artifacts:
- Trained CNN Model (model_final.h5)
- Parking-space positions (carposition.pkl)

B. Inference & Serving (online)
1. Video Source
- Local video file (car_test.mp4) or live camera feed
2. Video Processing Module
- Uses OpenCV to read frames and extract regions of interest (ROIs) based on carposition.pkl
3. Classification Module
- Loads trained CNN model (.h5) via TensorFlow/Keras and NumPy
- Classifies each ROI as “car” or “no car”
4. Overlay & Counting Module
5. Flask Web Application
- Routes in main.py (or app.py) define controllers for:
- Homepage (renders templates/index.html)
- /video_feed (streaming MJPEG frames)
- /space_count (JSON API returning current counts)
6. Frontend UI
- HTML template (templates/index.html) displaying live video and counts
7. Dependencies & Config
- requirements.txt (Flask, OpenCV, TensorFlow, Keras, NumPy, Pickle)

##### Relationships and Data Flow
- Video Source → Video Processing → Classification Module → Overlay/Counting →
- Streamed to Browser via /video_feed
- Count data exposed via /space_count API → Frontend UI
- Offline: Data Collection → Notebook → Model Training → Persist model & positions

##### Architectural Patterns and Principles
- MVC (Model–View–Controller) in Flask:
- Model: CNN model + parking-position data
- View: HTML template for UI
- Controller: Flask route functions handling video stream & API
- Separation of Concerns: training vs inference; processing pipeline vs web-serving
- Single responsibility: each module does one task (data collection, training, processing, serving)

##### Essential Elements
- Labels on every component (e.g., “OpenCV Frame Grabber”, “TensorFlow Classifier”)
- Compute modules vs stored artifacts vs external clients

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Offline Training Phase
  subgraph "Offline Training"
    direction TB
    DC["Data Collection Script"]:::training
    NB["Training Notebook"]:::training
    TA["Training Data Archive"]:::storage
    TF["Training Framework"]:::training
    MA["Trained Model (model_final.h5)"]:::storage
    PP["Parking‐Position Artifact (carposition.pkl)"]:::storage
  end

  DC -->|"generates raw data"| TA
  DC -->|"used by"| NB
  TA -->|"loaded by"| NB
  NB -->|"trains model with"| TF
  TF -->|"outputs"| MA
  TF -->|"outputs"| PP

  %% Inference & Serving Phase
  subgraph "Online Inference & Serving"
    direction TB
    VS["Video Source File"]:::external
    VP["OpenCV Frame Grabber"]:::inference
    CM["TensorFlow Classifier"]:::inference
    OC["Overlay & Counting Module"]:::inference
    FL["Flask Web Application"]:::inference
    UI["Frontend UI (Browser)"]:::frontend
    RI["requirements.txt"]:::storage
    TS["Auxiliary Test Script"]:::inference
  end

  VS -->|"frame"| VP
  PP -->|"reads positions"| VP
  VP -->|"ROI frames"| CM
  MA -->|"loads model"| CM
  CM -->|"classification result"| OC
  OC -->|"annotated frames"| FL
  OC -->|"counts JSON"| FL
  FL -->|"streams MJPEG"| UI
  FL -->|"serves JSON"| UI
  RI --> FL
  TS --> FL

  %% Click Events
  click DC "https://github.com/chando0185/car_parking_detection_space_count/blob/main/datacollection.py"
  click NB "https://github.com/chando0185/car_parking_detection_space_count/blob/main/Car Parking System Using Deep Learning.ipynb"
  click TA "https://github.com/chando0185/car_parking_detection_space_count/blob/main/train_data.zip"
  click MA "https://github.com/chando0185/car_parking_detection_space_count/blob/main/model_final.h5"
  click PP "https://github.com/chando0185/car_parking_detection_space_count/blob/main/carposition.pkl"
  click VS "https://github.com/chando0185/car_parking_detection_space_count/blob/main/car_test.mp4"
  click FL "https://github.com/chando0185/car_parking_detection_space_count/blob/main/main.py"
  click UI "https://github.com/chando0185/car_parking_detection_space_count/blob/main/templates/index.html"
  click RI "https://github.com/chando0185/car_parking_detection_space_count/blob/main/requirements.txt"
  click TS "https://github.com/chando0185/car_parking_detection_space_count/blob/main/test.py"

  %% Styles
  classDef training fill:#E6E6FA,stroke:#333,stroke-width:1px;
  classDef inference fill:#ADD8E6,stroke:#333,stroke-width:1px;
  classDef frontend fill:#98FB98,stroke:#333,stroke-width:1px;
  classDef storage fill:#FFA500,stroke:#333,stroke-width:1px;
  classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
