I am looking around how to reduce the brightness of the webcam image. Can you tell me how to do it?
I couldn't find anything ...
To increase the value I use this function (I increase the brightness with a trackbar):
def change_brightness(frame, value):
hsv = cv2.cvtColor(frame, 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
This is the full code:
cv2.namedWindow("VIDEO")
#cv2.createTrackbar("alpha", "VIDEO", 0, 4, nothing)
cv2.createTrackbar("gamma", "VIDEO", 50, 100, nothing)
while True:
k = cv2.waitKey(1)
_, frame = video.read()
frame = cv2.resize(frame, FRAME_DIM) # frame contiene l'immagine della webcam
frame = cv2.flip(frame, 1) # giro orizzontalmente (parametro = 1) l'immagine
#test = cv2.getTrackbarPos("alpha", "VIDEO")
test = cv2.getTrackbarPos("gamma", "VIDEO")
gamma = cv2.getTrackbarPos("gamma", "VIDEO")
frame = change_brightness(frame, gamma)
if (k % 256 == ord("q")): # PATH, folder_name, full_path, IMG_LABELquando premo "q" si chiude la webcam e la relativa finestra
cv2.destroyAllWindows()
break
camera = cv2.imshow("VIDEO", frame)