Dliang110 / TemplateMatcher

Scale and rotation invariant template matcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Template Matcher

In the project, we are locating the defining area as scale and rotation invariant in the map image using SIFT algorithm and return the coordinates of the matched location.

Why SIFT (Scale Invarient Feature Transform)?

There are tons of feature detection algorithm such as SIFT, SURF, FAST, BRISK, ORB, etc. Acording to tests, SIFT has low error-rate and better accuracy comparing to others. But, it tooks too much time to execute.

Table of Contents

Prerequisites

  • Quick install prerequisites
pip install -r requirements.txt
  • Package version list
python 3.7.13
opencv 4.5.5.64 
numpy 1.21.6
matplotlib 3.5.2

Help

python template_matcher.py -h

optional arguments:
  -h, --help           show this help message and exit
  --template TEMPLATE  The image to be used as template
  --map MAP            The image to be searched in
  --show               Shows result image
  --save-dir SAVE_DIR  Directory in which you desire to save the result image

Examples

1. Satellite Map Template Matching

Finding the exact location and coordinates of a rotated part of the satellite map in the satellite map.

python template_matcher.py --template 'examples\satellite-map\eminonu-satellite-map.jpg' --map 'examples\satellite-map\istanbul-satellite-map.jpg' --save-dir 'examples\satellite-map\output-satellite-map.jpg'

Template:


Map:


Result:


Coordinates:

[[[831.315   812.50635]]
 [[794.627   748.854  ]]
 [[728.32965 786.2521 ]]
 [[765.0782  850.3996 ]]]

2. Finding Maiden's Tower in Istanbul Map

Finding the exact location and coordinates of a rotated part of the satellite map in the satellite map.

python template_matcher.py --template 'examples\maidens-tower\maidens-tower.jpg' --map 'examples\maidens-tower\istanbul-map.jpg' --save-dir 'examples\maidens-tower\output-maidens-tower-location.jpg'

Template:


Map:


Result:


Coordinates:

[[[2538.456  1709.4415]]
 [[2531.6711 1715.0646]]
 [[2558.1897 1709.6547]]
 [[2533.1726 1710.5573]]]

3. Star Map Template Matching

Finding the exact location and coordinates of color overlayed, noised, and rotated a part of the star map in the star map.

python template_matcher.py --template 'examples\star-map\area-on-the-sky.jpg' --map 'examples\star-map\star-map.jpg' --show

Template:


Map:


Result:


Coordinates:

[[[390.81454 742.3058 ]]
 [[513.85657 933.92474]]
 [[755.19464 778.7366 ]]
 [[632.2348  587.18396]]]

Change Log

  • Project upgraded opencv 3.4.2 to opencv 4.5.5.64
  • Added quick installation for prerequisites

Referances

  1. Scale-Invariant Feature Transform

  2. Feature Matching + Homography to find Objects

  3. Template Matching

  4. Histogram Equalization

  5. A Review on Image Feature Detection and Description

About

Scale and rotation invariant template matcher


Languages

Language:Python 100.0%