How to fast change image brightness with python + OpenCV?

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

    Iterating over the whole image to make changes is not a very scalable option in opencv, Opencv provides a lot of methods and functions to perform the arithmetic operations on the given image.

    You may simply split the converted HSV image in the individual channels and then process the V channel accordingly as:

    img = cv2.imread('test.jpg') #load rgb image
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #convert it to hsv
    
    h, s, v = cv2.split(hsv)
    v += 255
    final_hsv = cv2.merge((h, s, v))
    
    img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2BGR)
    cv2.imwrite("image_processed.jpg", img)
    

提交回复
热议问题