File size: 3,781 Bytes
aad4f32
 
 
 
 
3c4966b
aad4f32
 
c7e9899
aad4f32
 
c7e9899
c5d647f
c7e9899
c5d647f
c7e9899
c5d647f
c7e9899
c5d647f
c7e9899
 
 
c5d647f
c7e9899
c5d647f
c7e9899
c5d647f
c7e9899
c5d647f
c7e9899
 
 
 
 
c5d647f
c7e9899
24dfe77
c7e9899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7500864
c7e9899
 
 
 
 
 
 
 
 
 
7500864
c7e9899
 
7500864
c7e9899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
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:

1. **Sliding** the template across all possible positions in the scene
2. **Computing** a similarity score at each position
3. **Identifying** the location with the highest similarity score

## πŸš€ Try It Live

**[Launch the Interactive Demo](https://huggingface.co/spaces/amithjkamath/template-matching)**

## ✨ 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

```bash
# 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)

```bash
make setup    # Initial setup
make run      # Run the app
make deploy   # Deploy to GitHub & HuggingFace
make help     # See all commands
```

### Manual Setup

```bash
# 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](https://github.com/astral-sh/uv) package manager (installed by setup.sh)

## πŸ› οΈ Development

See [CONTRIBUTING.md](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](CONTRIBUTING.md) for guidelines.

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](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:
- [OpenCV Web App with Streamlit](https://www.loginradius.com/blog/engineering/guest-post/opencv-web-app-with-streamlit/)
- [Finding Waldo: Feature Matching for OpenCV](https://medium.com/analytics-vidhya/finding-waldo-feature-matching-for-opencv-9bded7f5ab10)