utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:jsnu_Erya 作者: FantasRu 项目源码 文件源码
def get_color(im):
    '''
    Get the main color of a picture, by this color we can judge the status of a video is finished or not.
    '''
    im = Image.open(im)
    im = im.convert('RGBA')

    # generate thumbnails, reduce cpu pressure
    im.thumbnail((200, 200))
    max_score = None
    dominant_color = None
    for count, (r, g, b, a) in im.getcolors(im.size[0] * im.size[1]):
        saturation = colorsys.rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0)[1]
        y = min(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235)
        y = (y - 16.0) / (235 - 16)
        score = (saturation + 0.1) * count
        if score > max_score:
            max_score = score
            dominant_color = (r, g, b)

    return dominant_color
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号