简体   繁体   中英

Camera brightness is changing automatically in opencv python

I am working on one OpenCV project where I am processing realtime camera images and comparing with the previous frame. One thing noticed that the camera brightness keeps changing with time. Example: if some dark object comes it automatically increases the brightness of the background. and decrease for bright objects. Because of it, I am unable to process the background accurately

Is there any way to fix the camera properties?

This will help you then you can take the frame and process it as per your requiremens.

import cv2
import numpy as np
import face_recognition
import time


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

# camera device can be different for your computer. Try to change 0 to 1 or other if you get some error 
video=cv2.VideoCapture(0)

count=0
l=[]
while True:
        
    ret, frame = video.read()
    frame = increase_brightness(frame, value=100)#change the brighness as per your requiremens before only more the value more the brightness
    cv2.imshow("frame",frame)
 
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM