|
7 | 7 | from .NMS import NMS
|
8 | 8 |
|
9 | 9 | __all__ = ['NMS']
|
10 |
| -__version__ = '1.5.1' |
| 10 | +__version__ = '1.5.2' |
11 | 11 |
|
12 | 12 | def _findLocalMax_(corrMap, score_threshold=0.6):
|
13 | 13 | '''
|
@@ -82,15 +82,27 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
|
82 | 82 | else:
|
83 | 83 | xOffset=yOffset=0
|
84 | 84 |
|
85 |
| - ## 16-bit image are converted to 32-bit for matchTemplate |
86 |
| - if image.dtype == 'uint16': image = np.float32(image) |
| 85 | + ## OpenCv matchTemplates only support 8 or 32-bit ie cast 16-bit to 32-bit |
| 86 | + if image.dtype == 'uint16': |
| 87 | + image = np.float32(image) |
| 88 | + |
| 89 | + elif image.dtype == "float64": |
| 90 | + raise ValueError("64-bit not supported, max 32-bit") |
87 | 91 |
|
88 | 92 | listHit = []
|
89 | 93 | for templateName, template in listTemplates:
|
90 | 94 |
|
91 | 95 | #print('\nSearch with template : ',templateName)
|
92 |
| - ## 16-bit image are converted to 32-bit for matchTemplate |
93 |
| - if template.dtype == 'uint16': template = np.float32(template) |
| 96 | + |
| 97 | + if template.dtype == "float64": raise ValueError("64-bit not supported, max 32-bit") |
| 98 | + |
| 99 | + ## Make sure both images have same bittype and 8 or 32 bit |
| 100 | + if (template.dtype == "uint8" and image.dtype == "float32") or template.dtype == 'uint16': |
| 101 | + template = np.float32(template) |
| 102 | + |
| 103 | + # Separate if |
| 104 | + if template.dtype == "float32" and image.dtype == "uint8": |
| 105 | + image = np.float32(image) |
94 | 106 |
|
95 | 107 | ## Compute correlation map
|
96 | 108 | corrMap = cv2.matchTemplate(template, image, method)
|
@@ -155,10 +167,10 @@ def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=f
|
155 | 167 |
|
156 | 168 | Returns
|
157 | 169 | -------
|
158 |
| - Pandas DataFrame with 1 row per hit and column "TemplateName"(string), "BBox":(X, Y, Width, Height), "Score":float |
159 |
| - if N=1, return the best matches independently of the score_threshold |
160 |
| - if N<inf, returns up to N best matches that passed the score_threshold |
161 |
| - if N=inf, returns all matches that passed the score_threshold |
| 170 | + Pandas DataFrame with 1 row per hit and column "TemplateName"(string), "BBox":(X, Y, Width, Height), "Score":float |
| 171 | + if N=1, return the best matches independently of the score_threshold |
| 172 | + if N<inf, returns up to N best matches that passed the score_threshold |
| 173 | + if N=inf, returns all matches that passed the score_threshold |
162 | 174 | '''
|
163 | 175 | if maxOverlap<0 or maxOverlap>1:
|
164 | 176 | raise ValueError("Maximal overlap between bounding box is in range [0-1]")
|
|
0 commit comments