# smaranjitghose/movenet architecture

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

- Interactive diagram: https://gitdiagram.com/smaranjitghose/movenet
- Repository: https://github.com/smaranjitghose/movenet

## Overview

##### Project Type & Purpose
- This is a stand-alone Python pose-detection script that reads a video (or camera feed), runs TensorFlow Lite MoveNet Lightning SinglePose inference, draws the 17 keypoints and skeleton edges, and writes out (or displays) the annotated video.

##### Main Architectural Components
a. Input Module (Green parallelogram)
- Sources:
- File input: assets/input/demo.mp4 (or any other video via `input_video_path`)
- Camera capture: `cv2.VideoCapture(0 or 1)` for live feed
- Responsibility: Read raw video frames.
b. Preprocessing Component (Blue rectangle)
- Resize frame to model’s input size
- Normalize pixel values
- Convert to the tensor format required by TFLite Interpreter
- Model artifact: models/movenet_singlepose_lightning.tflite
- Runtime: TensorFlow Lite Interpreter
- Responsibility: Run single-pose detection per frame, output a 17×3 array of (y, x, score).
d. Postprocessing Component (Blue rectangle)
- Filter keypoints by confidence threshold (configurable in code)
- Normalized coordinates back to original frame dimensions
e. Visualization Module (Blue rectangle)
f. Output Module (Green parallelogram)
- File writer: cv2.VideoWriter to assets/output/result.mp4
- OR real-time display window via cv2.imshow

##### Relationships & Data Flow
Input → Preprocessing → Inference Engine → Postprocessing → Visualization → Output
- Branch from Input to “Live Capture” and back into Preprocessing to show optional real-time mode

##### Key Design Principles & Patterns
- Pipeline pattern: clearly separated stages for readability and maintainability
- Configurability: threshold and input source parameters centralized in main.py

##### Technologies & Frameworks
- Python3 (main.py)
- OpenCV (cv2) for I/O, preprocessing, drawing, and video writing
- numpy for tensor manipulation
- tflite-runtime or TensorFlow Lite Interpreter for model inference
- requirements.txt lists exact versions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Module
    Input["Input Module\n(File or Camera)"]:::io
    click Input "https://github.com/smaranjitghose/movenet/blob/master/assets/input/demo.mp4"
    click Input "https://github.com/smaranjitghose/movenet/blob/master/main.py"

    %% Pose Detection Pipeline
    subgraph "Pose Detection Pipeline"
        Preprocessing["Preprocessing\n(Resize, Normalize,\nTo Tensor)"]:::compute
        click Preprocessing "https://github.com/smaranjitghose/movenet/blob/master/main.py"

        InferenceEngine["TFLite Interpreter\n(Run Inference)"]:::compute
        click InferenceEngine "https://github.com/smaranjitghose/movenet/blob/master/main.py"

        ModelArtifact[(Model File\nmovenet_singlepose_lightning.tflite)]:::model
        click ModelArtifact "https://github.com/smaranjitghose/movenet/blob/master/models/movenet_singlepose_lightning.tflite"

        Postprocessing["Postprocessing\n(Filter, Map Coords)"]:::compute
        click Postprocessing "https://github.com/smaranjitghose/movenet/blob/master/main.py"

        Preprocessing -->|RawFrame| InferenceEngine
        InferenceEngine -->|PreprocessedTensor| Postprocessing
        ModelArtifact -.->|Loaded By| InferenceEngine
    end

    %% Visualization Module
    Visualization["Visualization Module\n(Draw Keypoints & Skeleton)"]:::compute
    click Visualization "https://github.com/smaranjitghose/movenet/blob/master/main.py"

    %% Output Module
    Output["Output Module\n(File Writer or Display)"]:::io
    click Output "https://github.com/smaranjitghose/movenet/blob/master/assets/output/result.mp4"
    click Output "https://github.com/smaranjitghose/movenet/blob/master/main.py"

    %% Data Flow
    Input -->|RawFrame| Preprocessing
    Postprocessing -->|Keypoints| Visualization
    Visualization -->|AnnotatedFrame| Output

    %% Configuration & Requirements
    Config["requirements.txt\n(Dependencies)"]:::config
    Orchestration["main.py\n(Orchestration & Params)"]:::config
    click Config "https://github.com/smaranjitghose/movenet/blob/master/requirements.txt"
    click Orchestration "https://github.com/smaranjitghose/movenet/blob/master/main.py"

    %% Legend
    subgraph "Legend"
        IO[Parallelogram = I/O Modules]:::io
        Compute[Rectangle = Compute Stages]:::compute
        Model[Cylinder = Model Artifact]:::model
        ConfigLegend["Gray = Config & Requirements"]:::config
    end

    %% Styles
    classDef io fill:#d4f8d4,stroke:#4caf50,stroke-width:2px;
    classDef compute fill:#d0e7ff,stroke:#2196f3,stroke-width:2px;
    classDef model fill:#ffe0b2,stroke:#ff9800,stroke-width:2px;
    classDef config fill:#f0f0f0,stroke:#9e9e9e,stroke-width:2px;
```
