我使用 raspberry pi 相机录制了一段视频,但视频的温度非常高,所以我使用以下代码来降低温度,但图像仍然看起来很苍白。图像中锥体的颜色看起来很暗淡。如何增加图像中的颜色强度/饱和度?或者我是否可以在重新编码时在相机中进行任何校准?。
import cv2
from PIL import Image
import numpy as np
kelvin_table = {
1000: (255,56,0),
1500: (255,109,0),
2000: (255,137,18),
2500: (255,161,72),
3000: (255,180,107),
3500: (255,196,137),
4000: (255,209,163),
4500: (255,219,186),
5000: (255,228,206),
5500: (255,236,224),
6000: (255,243,239),
6500: (255,249,253),
7000: (245,243,255),
7500: (235,238,255),
8000: (227,233,255),
8500: (220,229,255),
9000: (214,225,255),
9500: (208,222,255),
10000: (204,219,255)}
alpha = 1.5# Contrast control (1.0-3.0)
beta = 20 # Brightness control (0-100)
def convert_temp(image, temp):
r, g, b = kelvin_table[temp]
matrix = ( r / 255.0, 0.0, 0.0, 0.0,
0.0, g / 255.0, 0.0, 0.0,
0.0, 0.0, b / 255.0, 0.0 )
return image.convert('RGB', matrix)
cap = cv2.VideoCapture("./filename.mp4")
while True:
ret, frame = cap.read()
if ret:
###Color temp###
frame = Image.fromarray(frame.astype('uint8'),'RGB')
frame = convert_temp(frame, 3500)
frame = np.asarray(frame)
###constrast and brightness####
frame=cv2.addWeighted(frame,alpha,np.zeros(frame.shape, frame.dtype),0,beta)
cv2.imshow("frame",frame)
else:
break
if cv2.waitKey(60) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()