-
Notifications
You must be signed in to change notification settings - Fork 1
/
自动调节L值
49 lines (44 loc) · 1.68 KB
/
自动调节L值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sensor
import image
import time
##记得先执行sensor.set_auto_whitebal(False)和sensor.set_auto_gain(False) 否则变不了
l_value= 60
baoguang = 20000
baoguang_step = 1500
sensor.set_auto_exposure(False,baoguang)#设置感光度 这里至关重要
auto_exposure_flag = True
auto_exposure_first = True
while(True):
clock.tick()
# 捕获图像
img = sensor.snapshot()
# 计算图像的直方图
histogram = img.histogram()
histogram_statistics = histogram.get_statistics()
#print(histogram_statistics)
if auto_exposure_first:
for i in range(20):
img = sensor.snapshot()
# 计算图像的直方图
histogram = img.histogram()
histogram_statistics = histogram.get_statistics()
# 计算图像的直方图
histogram = img.histogram()
histogram_statistics = histogram.get_statistics()
# 提取 mode 值
if hasattr(histogram_statistics, "mode"):
mode_value = histogram_statistics.mode() # 调用 mode 方法
print("mode 值:", mode_value)
else:
print("histogram_statistics 对象没有 mode 方法")
if mode_value > 40:
baoguang -= baoguang_step
sensor.set_auto_exposure(False,baoguang)#设置感光度 这里至关重要
print("亮度减小")
elif mode_value < 30:
baoguang += baoguang_step
sensor.set_auto_exposure(False,baoguang)#设置感光度 这里至关重要
print("亮度增大")
else:
auto_exposure_first = False
#print("调节已结束")