ルーチン説明 99-テスト->カラーバーカラーテスト
import sensor, time
sensor.reset()
sensor.set_brightness(0)
sensor.set_saturation(3)
sensor.set_gainceiling(8)
sensor.set_contrast(2)
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
sensor.set_colorbar(True)
for i in range(0, 30):
image = sensor.snapshot()
t = [lambda r, g, b: r < 70 and g < 70 and b < 70,
lambda r, g, b: r < 70 and g < 70 and b > 200,
lambda r, g, b: r > 200 and g < 70 and b < 70,
lambda r, g, b: r > 200 and g < 70 and b > 200,
lambda r, g, b: r < 70 and g > 200 and b < 70,
lambda r, g, b: r < 70 and g > 200 and b > 200,
lambda r, g, b: r > 200 and g > 200 and b < 70,
lambda r, g, b: r > 200 and g > 200 and b > 200]
if (sensor.get_id() == sensor.OV7725):
t = t[::-1]
for i in range(0, 8):
avg = (0, 0, 0)
idx = 40*i+20
for off in range(0, 10):
rgb = image.get_pixel(idx+off, 120)
avg = tuple(map(sum, zip(avg, rgb)))
if not t[i](avg[0]/10, avg[1]/10, avg[2]/10):
raise Exception("COLOR BARS TEST FAILED. "
"BAR#(%d): RGB(%d,%d,%d)"%(i+1, avg[0]/10, avg[1]/10, avg[2]/10))
print("COLOR BARS TEST PASSED...")
Singtown Technology OpenMV
公式中国語ドキュメント機能説明: