Hi
For my project I try to create a finger tracking solution, where IR leds attached to a Plexi-screen highlights the finger and the position is tracked by the camera. In our first solution we used a webcam for this purpose: (TouchBox [Eurohaptics 2018 demo] - YouTube). in the next iteration we would like to us openMV, and first tests already look promising, but the IR Leds get very hot if we keep them running continuously.
So I thought it would be a good idea to sync them with the image capture frequency, but while it is clear to me how to control an IO pin to drive a relay or a transistor, its not clear how my python code should look like in order to make this work. My naive idea in pseudo code:
While
Switch on LED
capture image
Switch off LED
any suggestions are welcome.
cheers
martin
Hi, your code will work, but the LEDs will be on a long time before the frame actually starts. Try this instead, this will sync the LED pin to the frame start interrupt:
import sensor, image
from pyb import Pin
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
ir_led_pin = Pin('LED_IR', Pin.OUT_PP, Pin.PULL_NONE)
sensor.set_vsync_output(ir_led_pin)
while(True):
clock.tick()
img = sensor.snapshot()
ir_led_pin.off()
Interesting project, please keep us updated on your progress.
Thanks, your solution works.
The oscilloscope shows this will keep the LED’s switched off for 50% of the time, which is definitely better than before.
for future reference:
import sensor, image, time, pyb
ir_leds.off()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()
# create the pin to controll the IR Leds
ir_led_pin = pyb.Pin("P0", pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)
# tell the sensor to enable the pin when the capturing starts
sensor.set_vsync_output(ir_led_pin)
while(True):
clock.tick()
# Zoom in (higher) or out (lower) until you see enough of the image.
img = sensor.snapshot().lens_corr(strength = 2.4, zoom = 1.0)
# disable the IR pin once the sensor has finished.
ir_led_pin.off()
print(clock.fps())