Synchronise onboard IR LEDs with image capture while frame differencing

I am trying to use the onboard IR LEDs to illuminate a close-up object while doing frame differencing, by turning on the IR LEDs before the sensor snapshot and turning them off thereafter.

The problem is that when using the IR LEDs like that (in darkness), the brightness of the picture will vary with banding in upper or middle regions every few seconds, thus triggering my frame differencing algorithm too often because of what I suspect is irregular illumination timings from the LEDs or the image capture?

Since the Vishay LED’s rise and fall times are specified at 20 ns, I believe this is negligible, so I was trying to put some delay between the line that turns on the LEDs and the sensor.snapshot line, using both utime.sleep_ms and pyb.delay (and I am not sure what their difference is).

I tried values between 10 and 200 ms, but values below 100 ms do not get rid of banding and those above 100 ms introduce regular shifts between bright and dark images (even worse than no delay). I am wary of using higher values because they would decrease my frame rate too much.

What could be done to solve this problem and get homogenous, regular illumination from the IR LEDs while minimizing the power consumption with regular ON/OFF cycles?

Frames are captured all the time in the background, I don’t think that’s what you expect, you could disable that by calling sensor.set_framebuffers(1). Also if you turn on/off the LEDs, the automatic gain/exposure will change the image every time, you could try to disable auto gain/exposure to avoid that.

Thanks! Alright I will investigate that sensor.set_framebuffers and continuous background capture… sounds strange to me because I think of the script execution doing things line-by-line.

Indeed I am using fixed exposure and gain settings for frame differencing.

I am wondering whether an alternative would be to leave the LEDs on all the time instead of switchign them on and off all the time, if they don’t consume too much power?

Script is executed line by line, however frame capture is almost always running in the background to maintain high FPS. You can leave the LEDs I can’t remember the exactly current consumption though.

I tried using mono frame buffer with led.on before sensor.snapshot, and then, but it didn’t stabilise the image brightness. I have the LED on all the time now. This solved the image stability problem but doesn’t allow me to save power.

If you have an R1 camera (with OV7725) there’s also a set_auto_whitebal you should use to disable AWB, that might be the issue. Also you could use VSYNC callback to toggle the LED, see Examples->Board Control->