基于YUV图像的色彩调节

#!/usr/bin/python
#coding:utf-8

import cv2
import numpy as np

def cb():
    pass

if __name__ == "__main__":

    img = cv2.imread("test.jpg")
    assert img is not None, "test.jpg can not be opened!"
    img = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
    dst = np.array(img.shape, np.uint8)

    cv2.namedWindow('image')
    cv2.createTrackbar('U', 'image', 10, 20, cb)
    cv2.createTrackbar('V', 'image', 10, 20, cb)

    kernel = np.array([[0.299, 0.587, 0.114],
            [-0.1678, -0.3313, 0.5],
            [0.5, -0.4187, -0.0813]])

    while(1):
        cv2.imshow('image', dst)
        k=cv2.waitKey(1)&0xFFFF
        if k == 27:
            break

        u = cv2.getTrackbarPos('U', 'image')
        v = cv2.getTrackbarPos('V', 'image')

        print u,v

        #tmp = (img -[0, 127, 127])* [ 1, u/10.0 , v/10.0] + [0, 127, 127]
        tmp = img + [0, (u-10)*10.0, (v-10)*10.0]
        tmp2 = np.array(tmp, np.uint8)

        dst = cv2.cvtColor(tmp2, cv2.COLOR_YUV2BGR)

    cv2.destroyAllWindows()

效果:

基于YUV图像的色彩调节_第1张图片

基于YUV图像的色彩调节_第2张图片

你可能感兴趣的:(基于YUV图像的色彩调节)