2
2
3
3
4
4
class ImageUtils (object ):
5
-
6
5
@staticmethod
7
6
def image_match (actual_image_path , expected_image_path , tolerance = 0.05 ):
8
7
"""
@@ -24,9 +23,18 @@ def image_match(actual_image_path, expected_image_path, tolerance=0.05):
24
23
diff_image = actual_image .copy ()
25
24
for x in range (0 , width ):
26
25
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 )
30
38
31
39
diff_percent = 100 * float (diff_pixels ) / total_pixels
32
40
if diff_percent < tolerance :
0 commit comments