Skip to content

DevSenpai01/Template_Matching_Model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🧩 Template Matching Module – Object Detection from Larger Image (OpenCV)

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.


🔍 What It Does

  • 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

🧠 Core Features

  • ✅ Multiple Template Match Methods (TM_CCOEFF, TM_SQDIFF, etc.)
  • 🖼️ Match Visualization with Bounding Boxes
  • 📈 Match Confidence Threshold Control
  • 🔄 Easily Integrable as a CV Module

🛠️ Technologies Used

  • Language: Python
  • Libraries: OpenCV (cv2), NumPy, Matplotlib (for visualization)

📂 Folder Structure

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

🚀 Getting Started

# 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

⚙️ Parameters

  • --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)

📦 Use Case Integration

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.


💡 Key Learnings

  • 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

🤝 Contributing

Feel free to fork this and:

  • Add scale-invariant or multi-scale support
  • Improve threshold calibration
  • Integrate with Flask or streamlit UI modules

📄 License

This module is licensed under the MIT License.

“Find what you’re looking for — pixel by pixel.”

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published