Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

Commit e9ca162

Browse files
committed
Fix #52 Comparisons with empty masks
1 parent a479681 commit e9ca162

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/compare.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def compare_l2_norm_masked(source, capture, mask):
7373
# The L2 Error is summed across all pixels, so this normalizes
7474
max_error = (3 * numpy.count_nonzero(mask) * 255 * 255) ** 0.5
7575

76+
if not max_error:
77+
return 0
7678
return 1 - (error / max_error)
7779

7880
def compare_template(source, capture):
@@ -156,4 +158,6 @@ def compare_phash_masked(source, capture, mask):
156158
source_hash = imagehash.phash(source)
157159
capture_hash = imagehash.phash(capture)
158160

161+
if not source_hash + capture_hash:
162+
return 0
159163
return 1 - ((source_hash - capture_hash)/64.0)

0 commit comments

Comments
 (0)