首页 > 解决方案 > 相机亮度在opencv python中自动改变

问题描述

我正在处理一个 OpenCV 项目,我正在处理实时相机图像并与前一帧进行比较。有一件事注意到相机的亮度随着时间的推移而不断变化。示例:如果有一些深色物体出现,它会自动增加背景的亮度。对于明亮的物体,减少。因此,我无法准确处理背景

有没有办法修复相机属性?

标签: pythonopencvimage-processing

解决方案


这将帮助您,然后您可以根据您的要求获取框架并对其进行处理。

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

推荐阅读