美文网首页
HSV变换 — OpenCV& Python

HSV变换 — OpenCV& Python

作者: WZChan | 来源:发表于2017-10-09 15:07 被阅读0次
    import cv2
    
    img_path = 'C:/Users/WZChan/Desktop/'
    img = cv2.imread(img_path + 'tree.jpg')
    img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    turn_green_hsv = img_hsv.copy()
    turn_green_hsv[:, :, 0] = (turn_green_hsv[:, :, 0] + 15) % 180
    turn_green_img = cv2.cvtColor(turn_green_hsv, cv2.COLOR_HSV2BGR)
    cv2.imwrite(img_path + 'turn_green.jpg', turn_green_img)
    
    colorless_hsv = img_hsv.copy()
    colorless_hsv[:, :, 2] = 0.5 * colorless_hsv[:, :, 1]
    colorless_img = cv2.cvtColor(colorless_hsv, cv2.COLOR_HSV2BGR)
    cv2.imwrite(img_path + 'colorless.jpg', colorless_img)
    
    darker_hsv = img_hsv.copy()
    darker_hsv[:, :, 2] = 0.5 * darker_hsv[:, :, 2]
    darker_img = cv2.cvtColor(darker_hsv, cv2.COLOR_HSV2BGR)
    cv2.imwrite(img_path + 'darker.jpg', darker_img)
    
    tree.jpg turn_green.jpg colorless.jpg darker.jpg

    相关文章

      网友评论

          本文标题:HSV变换 — OpenCV& Python

          本文链接:https://www.haomeiwen.com/subject/jrcpyxtx.html