RAP Logo
Blocks ReferenceComputer vision

Template Matcher

Find specific image patterns (templates) within larger images using computer vision matching techniques.

Template Matcher Block

The Template Matcher block is designed for finding a specific image pattern (template) within a larger image. It compares an image template with another image to find how similar they are to each other, making it useful for object detection, pattern recognition, and image analysis tasks.

Overview

The Template Matcher uses computer vision techniques to locate and match template images within larger source images. It's particularly useful for finding specific elements, logos, or patterns in documents and images.

Configuration Options

Input Parameters

Image Path

  • Property: msg.payload.image_path
  • Type: string
  • Description: Specify the relative path of the main image on the shared storage
  • Example: "images/document1.png" or "document1.jpg"
  • Supported formats: .png, .PNG, .jpg, .JPG, .jpeg, .JPEG

Template Path

  • Property: msg.payload.template_path
  • Type: string
  • Description: Specify the relative path of the template image on the shared storage
  • Example: "images/template1.png" or "template1.jpg"
  • Supported formats: .png, .PNG, .jpg, .JPG, .jpeg, .JPEG

Minimum Match Percentage

  • Type: number
  • Range: 0 to 100
  • Default: 50
  • Description: Set how closely the template needs to match for it to be considered found in the main image
  • Note: A higher number means a stricter match is required. A lower number allows for more flexibility but may increase false matches.

How It Works

The Template Matcher compares an image (the template) with another image to find how similar they are to each other. It uses computer vision algorithms to:

  1. Load Images: Read both the main image and template from shared storage
  2. Feature Matching: Compare visual features between the template and regions of the main image
  3. Similarity Calculation: Calculate match confidence scores
  4. Result Filtering: Return matches that meet the minimum match percentage threshold

Output Format

The matcher provides results in a simple JSON format:

{
  "matched_template": "your_image_path.png",
  "number_of_features_matched": 100.0
}

This example means the template was matching with 100% confidence with the main image.

Use Cases

Logo Detection

Find company logos in documents:

Document image → Template Matcher (logo template) → Logo detection results

Form Field Recognition

Identify specific form fields or elements:

Form image → Template Matcher (field template) → Field location data

Quality Control

Check for specific elements in product images:

Product image → Template Matcher (quality mark template) → Quality verification

Document Processing

Find specific document elements:

Document → Template Matcher (signature template) → Signature detection

Common Patterns

Basic Template Matching

// Configuration
// Minimum Match Percentage: 70

// Input message:
{
  "payload": {
    "image_path": "documents/invoice_001.png",
    "template_path": "templates/company_logo.png"
  }
}

// Example flow:
// inject → Template Matcher → debug (match results)

Multiple Template Matching

// Process multiple templates against the same image
// Template 1: Logo detection
// Template 2: Signature detection
// Template 3: Stamp detection

// Example flow:
// image input → Template Matcher (logo) → Template Matcher (signature) → Template Matcher (stamp) → results

Batch Processing

// Process multiple images with the same template
// Configuration
// Minimum Match Percentage: 60

// Example flow:
// batch of images → Template Matcher → individual match results

Advanced Features

Match Confidence Scoring

The block provides detailed confidence scores:

{
  "matched_template": "logo_template.png",
  "number_of_features_matched": 85.5,
  "match_quality": "high",
  "coordinates": {
    "x": 150,
    "y": 200,
    "width": 100,
    "height": 50
  }
}

Multiple Match Detection

When multiple instances of a template are found:

{
  "matches": [
    {
      "template": "logo_template.png",
      "confidence": 92.3,
      "position": { "x": 100, "y": 150 }
    },
    {
      "template": "logo_template.png",
      "confidence": 88.7,
      "position": { "x": 300, "y": 400 }
    }
  ]
}

Tips for Best Results

Image Quality

  • Use clear, high-quality images for both the main image and the template
  • Ensure good contrast between the template and background
  • Avoid blurry or low-resolution images

Template Selection

  • Make sure your template image is a good representation of what you're trying to find
  • Use templates that are distinctive and not too generic
  • Consider the size - templates should be appropriately sized relative to the main image

Configuration

  • Try different Minimum Match Percentage values to find what works best for your images
  • Start with 70-80% for most applications
  • Lower to 50-60% if you need more flexibility
  • Increase to 90%+ for very strict matching

Environmental Factors

  • Be aware that changes in size, angle, or lighting between the template and where it appears in the main image can affect matching
  • Consider using multiple templates for the same object under different conditions
  • Test with various image qualities to ensure robustness

Common Issues and Solutions

Low Match Scores

  • Check image quality - ensure both images are clear and high-resolution
  • Verify template accuracy - make sure the template exactly matches what you're looking for
  • Adjust match percentage - lower the threshold if matches are being missed

False Positives

  • Increase match percentage - raise the threshold to require stricter matching
  • Improve template specificity - use more distinctive template images
  • Add post-processing - use additional validation logic after matching

Performance Issues

  • Optimize image sizes - use appropriately sized images for your use case
  • Consider image preprocessing - clean up images before template matching
  • Batch processing - process multiple images efficiently