Commit 3389802d by Vik Paruchuri

Fix logic in get_skin_ratio

parent da5ce144
...@@ -79,15 +79,16 @@ class ImageProperties(object): ...@@ -79,15 +79,16 @@ class ImageProperties(object):
Gets the ratio of skin tone colors in an image Gets the ratio of skin tone colors in an image
@return: True if the ratio is low enough to be acceptable, false otherwise @return: True if the ratio is low enough to be acceptable, false otherwise
""" """
im = self.image colors = self.image.getcolors(MAX_COLORS_TO_COUNT)
skin = sum([count for count, rgb in im.getcolors(im.size[0] * im.size[1]) if is_okay = True
rgb[0] > 60 and rgb[1] < (rgb[0] * 0.85) and rgb[2] < (rgb[0] * 0.7) and rgb[1] > (rgb[0] * 0.4) and if colors is not None:
rgb[2] > (rgb[0] * 0.2)]) skin = sum([count for count, rgb in colors if
bad_color_val = float(skin) / float(im.size[0] * im.size[1]) rgb[0] > 60 and rgb[1] < (rgb[0] * 0.85) and rgb[2] < (rgb[0] * 0.7) and rgb[1] > (rgb[0] * 0.4) and
if bad_color_val > .4: rgb[2] > (rgb[0] * 0.2)])
is_okay = False bad_color_val = float(skin) / len(colors)
else: if bad_color_val > .4:
is_okay = True is_okay = False
return is_okay return is_okay
def run_tests(self): def run_tests(self):
...@@ -95,8 +96,12 @@ class ImageProperties(object): ...@@ -95,8 +96,12 @@ class ImageProperties(object):
Does all available checks on an image to ensure that it is okay (size, skin ratio, colors) Does all available checks on an image to ensure that it is okay (size, skin ratio, colors)
@return: Boolean indicating whether or not image passes all checks @return: Boolean indicating whether or not image passes all checks
""" """
#image_is_okay = self.count_colors() and self.get_skin_ratio() and not self.image_too_large image_is_okay = False
image_is_okay = self.count_colors() and not self.image_too_large try:
image_is_okay = self.count_colors() and self.get_skin_ratio() and not self.image_too_large
except:
pass
return image_is_okay return image_is_okay
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment