0

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?

Suryaveer Singh
  • 577
  • 2
  • 13

1 Answers1

0

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
Suryaveer Singh
  • 577
  • 2
  • 13