Send Image to IDE

After taking a snapshot on the RT1062, I am processing the image stepwise and sequentially drawing on the image by adding rectangles, circles, text, etc, before taking another snapshot. I would like to see each sequential modification I make to the image on the lcd display and on the IDE. I use lcd.write to sequentially update the image on the display and that works great. How do I do the same to sequentially update the image on the IDE. I tried using print(img.to_jpeg(encode_for_ide = True)), but the next time I draw some text on the image, I get error message “Expected a mutable image”.

Do:

print(img.to_jpeg(encode_for_ide = True, copy=True))

The frame buffer is async polled by the IDE so it’s not necessarily easy to force the IDE to see any updates. But, the above should work.

Unfortunately that did not work. Here is example code that recreates the issue. On the LCD, the snapshot is displayed for 1s, then the same snapshot with the white square is displayed for 1s, then a new snapshot is taken. On the IDE, only the snapshot with the white square is displayed.

I see both the snapshot without the white square and one with the white square.

Anyway, add this to your code:

import omv
omv.disable_fb(True)

This will turn off the IDE pulling the frame buffer such that it will only update when you make the encode_for_ide calls.

Added this to the code and now there are no images showing on the IDE. LCD has images with the square flashing on and off.

Test_LCD_IDE_Write_Image_V1.py (2.4 KB)

I ran your code and see the following:

This is the behavior you wanted right?

Wait, I am using the H7 Plus. Let me try on the RT1062.

Okay, so, there’s going to be a challenge doing this with the RT1062. It’s using TinyUSB currently which has a different flushing policy for text compared to the H7 Plus. It doesn’t block when printing which means that it may drop characters.

Just do this:

while True:
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps())
    lcd.write(img, hint=image.ROTATE_270)
    img.flush()
    time.sleep_ms(1000)
    

    img.draw_rectangle(50,50,100,100,[255,255,255], thickness = 1, fill = True)
    lcd.write(img, hint=image.ROTATE_270)
    img.flush()
    time.sleep_ms(1000)

I’ve verified this works on the RT1062 and should work on all OpenMV Cams. The flush command marks the frame buffer to be sent to the IDE and then waiting for 1 second gives the IDE time to pull the frame.