How to fast change image brightness with python + OpenCV?

前端 未结 12 901
感动是毒
感动是毒 2020-12-05 10:42

I have a sequence of images. I need to average brightness of these images.

First example (very slow):

img = cv2.imread(\'test.jpg\')         


        
12条回答
  •  情话喂你
    2020-12-05 11:15

    Hope this is useful for someone

    @Divakar answer Python, OpenCV: Increasing image brightness without overflowing UINT8 array

    mImage = cv2.imread('image1.jpg')
    
    hsvImg = cv2.cvtColor(mImage,cv2.COLOR_BGR2HSV)
    
    value = 0
    
    vValue = hsvImg[...,2]
    hsvImg[...,2] = np.where((255-vValue)

    To decrease the brightness

    mImage = cv2.imread('image1.jpg')
    
    hsvImg = cv2.cvtColor(mImage,cv2.COLOR_BGR2HSV)
    
    # decreasing the V channel by a factor from the original
    hsvImg[...,2] = hsvImg[...,2]*0.6
    
    plt.subplot(111), plt.imshow(cv2.cvtColor(hsvImg,cv2.COLOR_HSV2RGB))
    plt.title('brightened image'), plt.xticks([]), plt.yticks([])
    plt.show()
    

提交回复
热议问题