[英]Camera brightness is changing automatically in opencv python
我正在處理一個 OpenCV 項目,我正在處理實時相機圖像並與前一幀進行比較。 有一件事注意到相機的亮度隨着時間的推移而不斷變化。 示例:如果出現一些較暗的 object,它會自動增加背景的亮度。 對於明亮的物體,減少。 因此,我無法准確處理背景
有沒有辦法修復相機屬性?
這將幫助您,然后您可以根據您的要求獲取框架並對其進行處理。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.