Skip to content

Commit d6ee500

Browse files
committed
refactor: count similar pixels as equal
1 parent 51c9a78 commit d6ee500

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

core/osutils/image_utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class ImageUtils(object):
5-
65
@staticmethod
76
def image_match(actual_image_path, expected_image_path, tolerance=0.05):
87
"""
@@ -24,9 +23,18 @@ def image_match(actual_image_path, expected_image_path, tolerance=0.05):
2423
diff_image = actual_image.copy()
2524
for x in range(0, width):
2625
for y in range(40, height):
27-
if actual_pixels[x, y] != expected_pixels[x, y]:
28-
diff_pixels += 1
29-
diff_image.load()[x, y] = (255, 0, 0)
26+
actual_pixel = actual_pixels[x, y]
27+
expected_pixel = expected_pixels[x, y]
28+
if actual_pixel != expected_pixel:
29+
actual_r = actual_pixel[0]
30+
actual_g = actual_pixel[1]
31+
actual_b = actual_pixel[2]
32+
expected_r = expected_pixel[0]
33+
expected_g = expected_pixel[1]
34+
expected_b = expected_pixel[2]
35+
if abs(actual_r + actual_g + actual_b - expected_r - expected_g - expected_b) > 15:
36+
diff_pixels += 1
37+
diff_image.load()[x, y] = (255, 0, 0)
3038

3139
diff_percent = 100 * float(diff_pixels) / total_pixels
3240
if diff_percent < tolerance:

0 commit comments

Comments
 (0)