- 在不同的拍摄环境下,可能会出现白平衡效果不正常的情况。用户可以自己根据实际使用情况调节白平衡参数。
- 以下opencv的调节代码只作参考。(该代码由RPi Camera (G)使用用户分享)
- import picamera
- import picamera.array
- import cv2
- from time import sleep
- import numpy as np
-
- def test_gcamera():
- cv2.namedWindow("img",0)
- with picamera.PiCamera() as camera:
- camera.resolution = (1920, 1080)
- camera.awb_mode = 'off'
- rg, bg = (1.8, 1.4)
- camera.awb_gains = (rg, bg)
- with picamera.array.PiRGBArray(camera) as output:
- for foo in camera.capture_continuous(output, 'rgb', use_video_port=True):
- img = cv2.cvtColor(output.array, cv2.COLOR_RGB2BGR)
- cv2.imshow("img", img)
- cv2.waitKey(1)
- cv2.imwrite("test.jpg",img)
- r, g, b = (np.mean(output.array[..., i]) for i in range(3))
- if abs(r - g) > 2:
- if r > g:
- rg -= 0.1
- else:
- rg += 0.1
- if abs(b - g) > 1:
- if b > g:
- bg -= 0.1
- else:
- bg += 0.1
- camera.awb_gains = (rg, bg)
- output.seek(0)
- output.truncate(0)
- if __name__=="__main__":
- test_gcamera()
|