python - 相机亮度在opencv python中自动改变
问题描述
我正在处理一个 OpenCV 项目,我正在处理实时相机图像并与前一帧进行比较。有一件事注意到相机的亮度随着时间的推移而不断变化。示例:如果有一些深色物体出现,它会自动增加背景的亮度。对于明亮的物体,减少。因此,我无法准确处理背景
有没有办法修复相机属性?
解决方案
这将帮助您,然后您可以根据您的要求获取框架并对其进行处理。
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
推荐阅读
- vba - 使用 Access 中的组合框过滤导航子表单
- python - Python 中的 list.copy() 返回相同的引用?
- python - In a Pandas dataframe how do I calculate the median value for each decile within each month
- system.reactive - 来自 Observable.FromEventPattern 的不兼容委托异常
- python - 将浮点数转换为特定子列表中的整数
- osgi - RedHat Fuse 7.5 - 无法部署功能
- python - 使用特殊字符在python中拆分
- ssl-certificate -
- c++ - std::cout 在打印变量与函数表达式时表现不同
- c# - 当给定类的元素不存在于小型 DOM 中时,检查它们的不可见性需要很长时间