# sreeharipremkumar/structure-from-motion architecture

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

- Interactive diagram: https://gitdiagram.com/sreeharipremkumar/structure-from-motion
- Repository: https://github.com/sreeharipremkumar/structure-from-motion

## Overview

##### Project type and purpose
- This is a C++ command‑line application for Structure‑From‑Motion (SfM), as indicated by the project name and presence of main.cpp, CMakeLists.txt, and an OpenCVSFM executable in the build directory.
- Its purpose is to take a set of images (e.g., in templeRing/) and compute camera poses and a sparse 3D point cloud.

##### File structure
- Top‑level:
- CMakeLists.txt – build configuration
- main.cpp – entry point
- templeRing/ – sample dataset (images and parameter files)
- build/ – generated build artifacts, Visual Studio projects, executable
- .vscode/ – editor settings
- No obvious “frontend” vs “backend” split; it’s a single native binary with modular SFM stages.
- Dependencies are managed via CMake and link against OpenCV (SFM module).

##### Insights from README
- Minimal; confirms this is Structure‑From‑Motion.

##### Main components
a. Input Module
- Image Loader (reads templeRing images)
- Parameter Loader (reads camera intrinsics from .txt)
b. Preprocessing
- Feature Detector / Descriptor (e.g., SIFT, ORB via OpenCV)
- Feature Matcher
c. SfM Pipeline
- Pairwise Pose Estimation (essential matrix, RANSAC)
- Incremental Reconstruction (triangulation, bundle adjustment)
d. Output Module
- 3D Point Cloud Exporter (PLY, OBJ)
- Camera Trajectory Output
e. External Dependencies
- OpenCV (core, imgproc, features2d, calib3d, sfm)
- CMake (build system)

##### Relationships and interactions
- Data flows left→right:
Images & Params → Preprocessing → SfM Pipeline → Outputs
- Feature Detector feeds into Matcher; Matcher & calibrations feed into Pose Estimation; Pose Estimation & existing points feed into Reconstruction loop; final results go to Exporter.
- All modules are compiled into a single executable (main.cpp calls each stage).

##### Architectural patterns / design principles
- Modular pipeline: each stage is decoupled and testable.
- Use of external libraries (OpenCV) for heavy lifting.
- CMake for cross‑platform builds; single monolithic service (no microservices).

##### Final checklist
- Landscape orientation
- External dependencies drawn separately but connected to modules that use them

## Diagram (Mermaid)

```mermaid
flowchart LR
    %% Input Layer
    subgraph "Input Module"
        direction LR
        Images["Images"]:::data
        Params["Camera Parameters"]:::data
        Loader["Image & Parameter Loader"]:::internal
    end

    %% Preprocessing Layer
    subgraph "Preprocessing"
        direction LR
        Detector["Feature Detector/Descriptor"]:::internal
        Matcher["Feature Matcher"]:::internal
    end

    %% SfM Pipeline
    subgraph "SfM Pipeline"
        direction LR
        PoseEst["Pairwise Pose Estimation"]:::internal
        Recon["Incremental Reconstruction"]:::internal
    end

    %% Output Layer
    subgraph "Output Module"
        direction LR
        PCExp["3D Point Cloud Exporter"]:::internal
        TrajExp["Camera Trajectory Exporter"]:::internal
    end

    %% External Dependencies and Build
    subgraph "Build & Dependencies"
        direction LR
        CMake["CMake Build System"]:::external
        OpenCV["OpenCV Library"]:::external
        VSCode["VSCode Settings"]:::external
        Executable["OpenCVSFM Executable"]:::exe
    end

    %% Main Executable Container
    Main["main.cpp / Executable"]:::container

    %% Data Source
    SampleData["templeRing Dataset"]:::data

    %% Data Flows
    SampleData -->|"Images"| Images
    SampleData -->|"Params"| Params
    Images -->|"Raw Images"| Loader
    Params -->|"Calibration Files"| Loader
    Loader -->|"Keypoints"| Detector
    Detector -->|"Descriptors"| Matcher
    Matcher -->|"Matches"| PoseEst
    PoseEst -->|"Camera Poses"| Recon
    Recon -->|"Sparse Points"| PCExp
    Recon -->|"Refined Poses"| TrajExp
    PCExp -->|"PLY/OBJ Files"| Executable
    TrajExp -->|"Trajectory File"| Executable

    %% Build Connections
    CMake -->|"Configures Build"| Executable
    CMake -->|"Links"| OpenCV
    Main -->|"Calls Stages"| Loader
    Main -->|"Calls Stages"| Detector
    Main -->|"Calls Stages"| Matcher
    Main -->|"Calls Stages"| PoseEst
    Main -->|"Calls Stages"| Recon
    Main -->|"Calls Stages"| PCExp
    Main -->|"Calls Stages"| TrajExp
    VSCode --> Executable

    %% Click Events
    click SampleData "https://github.com/sreeharipremkumar/structure-from-motion/tree/main/templeRing/"
    click Main "https://github.com/sreeharipremkumar/structure-from-motion/blob/main/main.cpp"
    click CMake "https://github.com/sreeharipremkumar/structure-from-motion/blob/main/CMakeLists.txt"
    click OpenCV "https://github.com/sreeharipremkumar/structure-from-motion/blob/main/CMakeLists.txt"
    click Executable "https://github.com/sreeharipremkumar/structure-from-motion/blob/main/build/Debug/OpenCVSFM.exe"
    click VSCode "https://github.com/sreeharipremkumar/structure-from-motion/tree/main/.vscode/"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef external fill:#98FB98,stroke:#333,stroke-width:1px;
    classDef data fill:#FFFF99,stroke:#333,stroke-width:1px;
    classDef exe fill:#DDA0DD,stroke:#333,stroke-width:1px;
    classDef container fill:#FFB6C1,stroke:#333,stroke-width:1px;
```
