Skip to content

Commit b825e42

Browse files
authored
Merge pull request #9 from multi-template-matching/template-mask
Support mask with template
2 parents 74d5e0c + 04b8179 commit b825e42

File tree

7 files changed

+968
-116
lines changed

7 files changed

+968
-116
lines changed

CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5+
6+
## [1.6.1] - 2020-08-20
7+
### Added
8+
- support mask for matchTemplates and findMatches as in cv2.matchTemplates with method 0 or 3
9+
- notebook tutorial with mask
10+
- CHANGELOG.MD
11+
12+
### Changed
13+
- better docstrings
14+
15+
## [1.6.0.post1] - 2020-08-04
16+
### Fixed
17+
- issue when no detection found (see Changed of version 1.5.3.post2)
18+
19+
20+
## [1.6.0] - 2020-08-03
21+
### Changed
22+
- NMS is now using the opencv `cv2.dnn.NMSBoxes` function
23+
- use timeit for benchmark in example notebook
24+
25+
### Removed
26+
- `MTM.NMS.Point_in_Rectangle` and `MTM.NMS.computeIoU` as they are not used anymore for the NMS
27+
28+
## [1.5.3.post2] - 2020-08-04
29+
### Fixed
30+
- issue when no detection found (see Changed)
31+
32+
### Changed
33+
- `MTM.findMatches` return a dataframe with proper column names (not just empty)
34+
- better handle the different opencv matchTemplate methods
35+
36+
## [1.5.3.post1] - 2020-05-11
37+
### Removed
38+
- remove the hardcoded version requirement for opencv-python-headless in setup.py
39+
40+
### Added
41+
- MTM version is now defined in a dedicated version.py file
42+
43+
## [1.5.3] - 2020-04-28
44+
### Added
45+
- `MTM.computeScoreMap` which is like `cv2.matchTemplate` but checking for image types
46+
47+
48+
## [1.5.2] - 2019-12-19
49+
### Changed
50+
- `MTM.findMatches` automatically cast 16-bit images and/or template to 32-bit
51+
52+
## [1.5.1] - 2019-10-10
53+
### Changed
54+
- use pandas dataframe to return list of hits for `MTM.matchTemplates` and `MTM.findMatches`

MTM/NMS.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
Non-Maxima Supression (NMS) for match template
3+
Non-Maxima Supression (NMS) for match template.
4+
45
From a pool of bounding box each predicting possible object locations with a given score,
56
the NMS removes the bounding boxes overlapping with a bounding box of higher score above the maxOverlap threshold
67
78
This effectively removes redundant detections of the same object and still allow the detection of close objects (ie small possible overlap)
89
The "possible" allowed overlap is set by the variable maxOverlap (between 0 and 1) which is the ratio Intersection over Union (IoU) area for a given pair of overlaping BBoxes
910
11+
Since version 1.6.0 the NMS is assured by opencv cv2.dnn.NMSBoxes function
1012
1113
@author: Laurent Thomas
1214
"""
@@ -15,33 +17,37 @@
1517

1618

1719
def NMS(tableHit, scoreThreshold=0.5, sortAscending=False, N_object=float("inf"), maxOverlap=0.5):
18-
'''
19-
Perform Non-Maxima supression : it compares the hits after maxima/minima detection, and removes the ones that are too close (too large overlap)
20-
This function works both with an optionnal threshold on the score, and number of detected bbox
21-
22-
if a scoreThreshold is specified, we first discard any hit below/above the threshold (depending on sortDescending)
23-
if sortDescending = True, the hit with score below the treshold are discarded (ie when high score means better prediction ex : Correlation)
24-
if sortDescending = False, the hit with score above the threshold are discared (ie when low score means better prediction ex : Distance measure)
25-
26-
Then the hit are ordered so that we have the best hits first.
27-
Then we iterate over the list of hits, taking one hit at a time and checking for overlap with the previous validated hit (the Final Hit list is directly iniitialised with the first best hit as there is no better hit with which to compare overlap)
20+
"""
21+
Perform Non-Maxima Supression (NMS).
2822
29-
This iteration is terminate once we have collected N best hit, or if there are no more hit left to test for overlap
23+
it compares the hits after maxima/minima detection, and removes detections overlapping above the maxOverlap
24+
Also removes detections that do not satisfy a minimum score
3025
31-
INPUT
32-
- tableHit : (Panda DataFrame) Each row is a hit, with columns "TemplateName"(String),"BBox"(x,y,width,height),"Score"(float)
26+
INPUT
27+
- tableHit : Pandas DataFrame
28+
List of potential detections as returned by MTM.findMatches.
29+
Each row is a hit, with columns "TemplateName"(String),"BBox"(x,y,width,height),"Score"(float).
3330
34-
- scoreThreshold : Float (or None), used to remove hit with too low prediction score.
35-
If sortAscending=False (ie we use a correlation measure so we want to keep large scores) the scores above that threshold are kept
36-
If True (we use a difference measure ie we want to keep low score), the scores below that threshold are kept
37-
38-
- N_object : maximum number of hit to return. Default=-1, ie return all hit passing NMS
39-
- maxOverlap : float between 0 and 1, the maximal overlap authorised between 2 bounding boxes, above this value, the bounding box of lower score is deleted
40-
- sortAscending : use True when low score means better prediction (Difference-based score), True otherwise (Correlation score)
31+
- scoreThreshold : Float, used to remove low score detections.
32+
If sortAscending=False, ie when best detections have high scores (correlation method), the detections with score below the threshold are discarded.
33+
If sortAscending=True, ie when best detections have low scores (difference method), the detections with score above the threshold are discarded.
34+
35+
- sortAscending : Boolean
36+
use True when low score means better prediction (Difference-based score), False otherwise (Correlation score).
37+
38+
- N_object : int or infinity/float("inf")
39+
maximum number of best detections to return, to use when the number of object is known.
40+
Otherwise Default=infinity, ie return all detections passing NMS.
41+
42+
- maxOverlap : float between 0 and 1
43+
the maximal overlap (IoU: Intersection over Union of the areas) authorised between 2 bounding boxes.
44+
Above this value, the bounding box of lower score is deleted.
45+
4146
42-
OUTPUT
43-
Panda DataFrame with best detection after NMS, it contains max N detection (but potentially less)
44-
'''
47+
Returns
48+
-------
49+
Panda DataFrame with best detection after NMS, it contains max N detections (but potentially less)
50+
"""
4551
listBoxes = tableHit["BBox"].to_list()
4652
listScores = tableHit["Score"].to_list()
4753

0 commit comments

Comments
 (0)