Update MLX example

This commit is contained in:
iabdalkader 2016-01-18 19:29:50 +02:00
parent ab3b36c504
commit f28d3f6235

View File

@ -1,33 +1,38 @@
import sensor, lcd, mlx, time, led, gpio import sensor, mlx, time
lcd.init() # Initialize the MLX module
mlx.init() mlx.init()
# Reset sensor
sensor.reset() sensor.reset()
# Set sensor settings
sensor.set_contrast(1)
sensor.set_brightness(0)
sensor.set_saturation(2)
sensor.set_pixformat(sensor.RGB565) sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) sensor.set_framesize(sensor.QQVGA)
thermal_on = True #The following registers fine-tune the window to align it with the FIR sensor.
sensor.__write_reg(0xFF, 0x01)
def switch_cb(line): #HSTART/HSTOP
global thermal_on sensor.__write_reg(0x17, 0x19)
if (line == 9): sensor.__write_reg(0x18, 0x43)
led.toggle(led.IR)
if (line == 12):
thermal_on = not thermal_on
gpio.EXTI(gpio.PB2, switch_cb)
gpio.EXTI(gpio.PB3, switch_cb)
# FPS clock
clock = time.clock() clock = time.clock()
while (True): while (True):
clock.tick() clock.tick()
rgb = sensor.snapshot() # Capture an image
rgb = rgb.scaled((128, 160)) image = sensor.snapshot()
if (thermal_on):
ir = mlx.read() # Capture an FIR image
x=ir.rainbow() ir = mlx.read(mlx.RAINBOW)
x=ir.scale((64, 160))
#rgb.blend(ir, (rgb.w/2-ir.w/2, rgb.h/2-ir.h/2), 0.4) # Scale the image and belnd it with the framebuffer
rgb.blend(ir, (32, 0, 0.6)) ir.scale((160, 32))
lcd.write_image(rgb) image.blend(ir, (0, 48, 0.6))
print(clock.fps())
# Print FPS.
print(clock.fps())