Spaces:
Sleeping
title: Template Matching Demo
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
short_description: Interactive demonstration of template matching with Waldo
π Template Matching Demo
An interactive educational tool that demonstrates how template matching works using computer vision. Learn by doing - click and drag to explore how computers find objects in images!
π― What is Template Matching?
Template Matching is a simple yet powerful computer vision method that finds the location of a template image within a larger scene by:
- Sliding the template across all possible positions in the scene
- Computing a similarity score at each position
- Identifying the location with the highest similarity score
π Try It Live
β¨ Features
- π±οΈ Interactive Template Placement: Click anywhere on the image to test template matching
- π Real-time Correlation Scores: See quantitative match scores (0.0-1.0) with color coding
- π¬ Zoomed Comparison View: Side-by-side visualization of template vs. current patch
- π¨ Educational Heatmaps: Understand how correlation works across the entire scene
- π― Instant Feedback: Learn through exploration and immediate visual feedback
π» Run Locally
Quick Start
# Clone the repository
git clone https://github.com/amithjkamath/template-matching.git
cd template-matching
# Run setup (installs uv and dependencies)
./setup.sh
# Run the app
./run_local.sh
Using Make (Alternative)
make setup # Initial setup
make run # Run the app
make deploy # Deploy to GitHub & HuggingFace
make help # See all commands
Manual Setup
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync --no-build-isolation
# Run the app
uv run --no-build-isolation streamlit run app.py
π Requirements
- Python 3.11 or higher
- uv package manager (installed by setup.sh)
π οΈ Development
See CONTRIBUTING.md for detailed development setup and guidelines.
π What situations could this method be applied to?
Template matching works best when:
- β The template is exactly replicated in the scene
- β Same scale (size) and orientation
- β No rotation or geometric transformations
- β Similar lighting conditions
β οΈ When would it not work?
Template matching struggles with:
- β Scale changes (different sizes)
- β Rotation or perspective changes
- β Significant lighting/color differences
- β Partial occlusions
π¬ Better Alternatives?
For scenarios with transformations, consider feature-based matching methods:
- SIFT (Scale-Invariant Feature Transform)
- SURF (Speeded-Up Robust Features)
- ORB (Oriented FAST and Rotated BRIEF)
- AKAZE (Accelerated-KAZE)
These methods are more robust to scale, rotation, and illumination changes.
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π¨ Image Attribution
Images from "Where's Waldo?" are copyrighted by their original owners and are used here purely for educational purposes.
π Acknowledgments
Inspired by: