This module implements template matching using OpenCV to detect and localize smaller objects (templates) within a larger image. Designed as a plug-and-play component of a larger computer vision-based application, it serves use cases such as logo detection, icon recognition, and UI element localization.
- Takes a template image and a larger input image
- Uses
cv2.matchTemplate()to scan for best matches - Draws bounding boxes around the detected regions
- Returns coordinates and confidence scores
- ✅ Multiple Template Match Methods (TM_CCOEFF, TM_SQDIFF, etc.)
- 🖼️ Match Visualization with Bounding Boxes
- 📈 Match Confidence Threshold Control
- 🔄 Easily Integrable as a CV Module
- Language: Python
- Libraries: OpenCV (cv2), NumPy, Matplotlib (for visualization)
template-matching-module/
├── templates/ # Template images
├── inputs/ # Larger input images
├── matched_outputs/ # Result images with bounding boxes
├── template_matcher.py # Core matching logic
└── README.md
# Clone this module
git clone https://github.com/yourusername/template-matching-module.git
cd template-matching-module
# Install dependencies
pip install opencv-python numpy matplotlib
# Run the template matcher
python template_matcher.py --template templates/logo.png --image inputs/screen.png --method TM_CCOEFF_NORMED--template: Path to the template image--image: Path to the larger image--method: (Optional) Template match method (e.g., TM_CCOEFF, TM_SQDIFF)--threshold: (Optional) Match confidence threshold (default: 0.8)
You can import this as a module in larger applications:
from template_matcher import find_template_matches
matches = find_template_matches("inputs/image.jpg", "templates/icon.png", threshold=0.85)Each match includes bounding box coordinates and confidence score.
- Template matching works well for identical scale & rotation
- Performance drops if templates are scaled or transformed
- Useful for rapid prototyping and fixed-layout recognition tasks
Feel free to fork this and:
- Add scale-invariant or multi-scale support
- Improve threshold calibration
- Integrate with Flask or streamlit UI modules
This module is licensed under the MIT License.
“Find what you’re looking for — pixel by pixel.”