How to fast change image brightness with python + OpenCV?

前端 未结 12 844
感动是毒
感动是毒 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:19

    I know this question is a bit old, but I thought I might post the complete solution that worked for me (takes care of the overflow situation by saturating at 255):

    def increase_brightness(img, value=30):
        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        h, s, v = cv2.split(hsv)
    
        lim = 255 - value
        v[v > lim] = 255
        v[v <= lim] += value
    
        final_hsv = cv2.merge((h, s, v))
        img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2BGR)
        return img
    

    This can be used as follows:

    frame = increase_brightness(frame, value=20)
    

提交回复
热议问题