@@ -35,8 +35,8 @@ def process_binary(img):
3535 solver = BinarySolver (img )
3636 return solver .solve ()
3737
38- def process_color (img , color_count , timer ):
39- solver = ColorSolver (img , color_count , timer )
38+ def process_color (img , color_count , tolerance , timer ):
39+ solver = ColorSolver (img , color_count , tolerance , timer )
4040 return solver .solve ()
4141
4242def validate_args (args ):
@@ -56,12 +56,17 @@ def validate_args(args):
5656 if not only_numbers :
5757 return False
5858
59+ tolerance = args .get ("tolerance" )
60+ if tolerance is not None and tolerance < 0 :
61+ return False
62+
5963 return SimpleNamespace (
60- crop_box = box ,
61- solver = solver ,
62- url = args .get ('url' ),
63- raw = args .get ('raw' ),
64- color_count = args .get ('color_count' ),
64+ crop_box = box ,
65+ solver = solver ,
66+ url = args .get ("url" ),
67+ raw = args .get ("raw" ),
68+ color_count = args .get ("color_count" ),
69+ tolerance = args .get ("tolerance" ),
6570 )
6671
6772def invalid_args ():
@@ -87,6 +92,10 @@ def index():
8792 color_count = args .color_count
8893 raw = args .raw
8994 crop_box = args .crop_box
95+ tolerance = args .tolerance
96+
97+ if tolerance is None :
98+ tolerance = 0.2
9099
91100 try :
92101 timer = Timer ()
@@ -105,7 +114,7 @@ def index():
105114
106115 else :
107116 timer .start_timer ('Color Solver - Total' )
108- solved = process_color (img , color_count , timer )
117+ solved = process_color (img , color_count , tolerance , timer )
109118 timer .end_timer ()
110119
111120 compound_paths , colors , width , height = solved
@@ -122,7 +131,7 @@ def index():
122131 timer .end_timer ()
123132
124133 timer .start_timer ('Bounds Creation' )
125- bounds = compound_path_list_bounds (compound_paths )
134+ bounds = compound_path_list_bounds (compound_paths , tolerance )
126135 timer .end_timer ()
127136
128137 app .logger .info (timer .timelog ())
0 commit comments