# dennisliu1993/fastest_image_pattern_matching architecture

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

- Interactive diagram: https://gitdiagram.com/dennisliu1993/fastest_image_pattern_matching
- Repository: https://github.com/dennisliu1993/fastest_image_pattern_matching

## Overview

##### Project type and purpose
- This is a native C++/MFC desktop application (MatchTool) for high-speed, rotation-invariant template matching using OpenCV’s Normalized Cross Correlation.
- It also produces platform-specific shared libraries (.so) and Python bindings (via Pybind11 and custom Neon SIMD code) for Unix/ARM and Linux, plus C++/MFC DLLs for .NET and Windows Python use.

##### File structure
- Top-level directories/files:
- MatchTool/ (all C++ source, headers, MFC resources, solution/project files)
- Test Images/ & Result Images/ (sample I/O for demos)
- Manual Image/Gif, PDF papers (documentation/resources)
- Key source modules in MatchTool/:
- Core algorithm: MatchTool.cpp/h, CvvImage.cpp/h, framework.h
- UI layer: MatchToolDlg.cpp/h, resource files (.rc, resource.h)
- Platform adapters: arm_version.cpp, x86_ubuntu_linux.cpp, ExeDir
- Precompiled header: pch.h/cpp
- Build & deployment artifacts:
- MatchTool.sln, .vcxproj, filters, user files
- Shared-object entry points for Python (.so)
- Language/resource files (MatchTool.Lang)

##### Pull architecture insights from the README
- Core engine features: image pyramid search, rotation invariance, SIMD‐accelerated convolution, custom GetNextMaxLoc optimizer
- Multiple build targets:
- Windows GUI (MFC)
- Unix/ARM64 & Linux .so (via Neon SIMD)
- Pybind11 wrapper for cross-platform Python integration
- .NET C++/MFC DLL for C#
- External dependencies: OpenCV (image processing), Python runtime, .NET runtime

##### Main components
A. UI Layer (MFC Desktop App)
- MatchToolDlg (drag-and-drop GUI)
- Resource files (.rc, dialogs, language packs)
B. Core Algorithm Library
- TemplateMatchingEngine (classes: MatchTool, CvvImage, framework)
- Optimization modules (SIMD routines, pyramid search, GetNextMaxLoc)
C. Platform Adapters & Wrappers
- Windows native build (.exe, .dll)
- Python bindings
- Neon-SIMD .so (ARM64 MacOS, Ubuntu)
- Pybind11 .so (cross-platform)
- .NET C++/MFC DLL
D. External Services/Libraries
- OpenCV (image I/O, rotation, convolution primitives)
- Python interpreter (.so consumers)
- Windows/.NET runtime

##### Relationships & data flow
- UI Layer → Core Algorithm: passes source & template images, parameters → returns result list (score, angle, position)
- Core Algorithm ↔ OpenCV: calls OpenCV APIs for rotation, convolution, image pyramid
- Core Algorithm ↔ SIMD modules: invokes platform-specific acceleration (Neon, x86)
- Wrappers → Core Algorithm: exposes C++ engine functions to Python/.NET
- Test/Result Images: consumed by UI and engine during demos & benchmarks

##### Architectural patterns & design principles
- Layered Architecture: clear separation UI ↔ Core ↔ Platform Adapters ↔ External libs
- Adapter Pattern: platform-specific code encapsulated in arm_version.cpp and x86_ubuntu_linux.cpp
- Strategy Pattern: interchangeable optimization strategies (SIMD vs. non-SIMD, pyramid vs. full scan)
- Modular Build Configurations: solution file defines multiple targets (Debug/Release, OpenCV4.X, Python, .NET)

##### Essential details
- Solution/project file as the orchestrator that builds all targets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        UI_Dlg["MatchToolDlg"]:::ui
        UI_RC["MatchTool.rc"]:::ui
        UI_RC2["res/MatchTool.rc2"]:::ui
        UI_ResH["resource.h"]:::ui
        UI_Lang["MatchTool.Lang"]:::ui
        UI_TargetVer["targetver.h"]:::ui
    end

    %% Core Engine
    subgraph "Core Engine"
        direction TB
        Core_Main["MatchTool.cpp / MatchTool.h"]:::core
        Core_Cvv["CvvImage.cpp / CvvImage.h"]:::core
        Core_Framework["framework.h"]:::core
        Core_PCH["pch.cpp / pch.h"]:::core
    end

    %% Platform Adapters & Wrappers
    subgraph "Platform Adapters & Wrappers"
        direction TB
        Adapter_ARM["arm_version.cpp"]:::adapter
        Adapter_x86["x86_ubuntu_linux.cpp"]:::adapter
        Adapter_ExeDir["ExeDir"]:::adapter
    end

    %% Build Artifacts
    subgraph "Build Artifacts"
        direction TB
        Artifact_Sln["MatchTool.sln"]:::artifact
        Artifact_VCX["MatchTool.vcxproj"]:::artifact
        Artifact_Filters["MatchTool.vcxproj.filters"]:::artifact
        Artifact_User["MatchTool.vcxproj.user"]:::artifact
        Artifact_Git[".gitignore"]:::artifact
        Artifact_License["LICENSE"]:::artifact
        Artifact_Readme["README.md"]:::artifact
    end

    %% Sample I/O Resources
    subgraph "Sample I/O Resources"
        direction TB
        IO_Test["Test Images/"]:::io
        IO_Result["Result Images/"]:::io
        IO_PDF1["Template Matching using Fast Normalized Cross Correlation.pdf"]:::io
        IO_PDF2["computers_and_electrical_engineering_an_accelerating_cpu_based_correlation-based_image_alignment.pdf"]:::io
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        Ext_OpenCV["OpenCV"]:::external
        Ext_Python["Python Runtime"]:::external
        Ext_DotNet[".NET Runtime"]:::external
    end

    %% Connections
    UI_Dlg -->|"invokes core"| Core_Main
    UI_Dlg -->|"uses resources"| UI_RC
    UI_Dlg --> UI_RC2
    UI_Dlg --> UI_ResH
    UI_Dlg --> UI_Lang
    UI_Dlg --> UI_TargetVer

    IO_Test -->|"loads images"| UI_Dlg
    IO_Test -->|"testbench input"| Core_Main
    Core_Main -->|"wraps algorithms"| Core_Cvv
    Core_Main --> Core_Framework
    Core_Main --> Core_PCH

    Core_Main -->|"calls OpenCV APIs"| Ext_OpenCV
    Core_Main -->|"uses SIMD adapters"| Adapter_ARM
    Core_Main --> Adapter_x86

    Adapter_ARM -->|"exposed via"| Ext_Python
    Adapter_x86 --> Ext_Python
    Adapter_ARM -->|"build target"| Artifact_Sln
    Adapter_x86 --> Artifact_Sln
    Adapter_ExeDir --> Core_Main

    Artifact_Sln --> Artifact_VCX
    Artifact_Sln --> Artifact_Filters
    Artifact_Sln --> Artifact_User
    Artifact_Sln --> Artifact_Git
    Artifact_Sln --> Artifact_License
    Artifact_Sln --> Artifact_Readme

    Ext_Python -->|"loads .so"| Adapter_ARM
    Ext_Python --> Adapter_x86
    Ext_Python --> Adapter_ExeDir

    Ext_DotNet -->|"loads DLL"| Adapter_ExeDir

    Core_Main --> IO_Result
    UI_Dlg --> IO_Result

    %% Click Events
    click UI_Dlg "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchToolDlg.cpp"
    click UI_Dlg "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchToolDlg.h"
    click UI_RC "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.rc"
    click UI_RC2 "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/res/MatchTool.rc2"
    click UI_ResH "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/resource.h"
    click UI_Lang "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.Lang"
    click UI_TargetVer "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/targetver.h"

    click Core_Main "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.cpp"
    click Core_Main "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.h"
    click Core_Cvv "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/CvvImage.cpp"
    click Core_Cvv "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/CvvImage.h"
    click Core_Framework "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/framework.h"
    click Core_PCH "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/pch.cpp"
    click Core_PCH "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/pch.h"

    click Adapter_ARM "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/arm_version.cpp"
    click Adapter_x86 "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/x86_ubuntu_linux.cpp"
    click Adapter_ExeDir "https://github.com/dennisliu1993/fastest_image_pattern_matching/tree/main/MatchTool/ExeDir"

    click Artifact_Sln "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.sln"
    click Artifact_VCX "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.vcxproj"
    click Artifact_Filters "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.vcxproj.filters"
    click Artifact_User "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/MatchTool/MatchTool.vcxproj.user"
    click Artifact_Git "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/.gitignore"
    click Artifact_License "https://github.com/dennisliu1993/fastest_image_pattern_matching/tree/main/LICENSE"
    click Artifact_Readme "https://github.com/dennisliu1993/fastest_image_pattern_matching/blob/main/README.md"

    click IO_Test "https://github.com/dennisliu1993/fastest_image_pattern_matching/tree/main/Test Images/"
    click IO_Result "https://github.com/dennisliu1993/fastest_image_pattern_matching/tree/main/Result Images/"

    %% Styles
    classDef ui fill:#E8F1FA,stroke:#5B9BD5,stroke-width:1px
    classDef core fill:#E6F4EA,stroke:#2E7D32,stroke-width:1px
    classDef adapter fill:#FFF4E5,stroke:#ED6C02,stroke-width:1px
    classDef external fill:#F2F2F2,stroke:#666666,stroke-width:1px
    classDef artifact fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
    classDef io fill:#FFFDE7,stroke:#F9A825,stroke-width:1px
```
