detect_color.py 文件源码

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

项目:political-ad-classifier 作者: BoudhayanBanerjee 项目源码 文件源码
def checkBluePixel(inputPath):
    """
    docstring
    """
    im = cv2.imread(inputPath, 1)
    # Convert BGR to HSV
    hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
    # define range of blue color in HSV
    lower_blue = np.array([110, 50, 50])
    upper_blue = np.array([130, 255, 255])
    # Threshold the HSV image to get only blue colors
    mask = cv2.inRange(hsv, lower_blue, upper_blue)
    # Bitwise-AND mask and original image
    res = cv2.bitwise_and(im, im, mask=mask)
    # save temp image
    cv2.imwrite(os.path.join(TEMP, 'temp.png'), res)
    ct = ColorThief(os.path.join(TEMP, 'temp.png'))
    palette = ct.get_palette(color_count=5)
    for p in palette:
        r = p[0]
        g = p[1]
        b = p[2]
        bgr = np.uint8([[[p[2], p[1], p[0]]]])
        hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
        h = hsv[0][0][0]
        s = hsv[0][0][1]
        v = hsv[0][0][2]
        if ((h >= 110 and h <= 130) and (s >= 50 and s <= 255) and (v >= 50 and v <= 255)):
            return True
            break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号