Memory Error, out of fast Frame Buffer Stack

I am having some issues with the OpenMV library and urgently need some help.

  1. I have imported one 320x240 24-bit grayscale in bmp format picture successfully. The image size is about 225KB. (see attached jpg file. OpenMV does not support jpg file, only bmp.)

  2. Some basic library function calls won’t run due to memory issues. Here is one example. We are trying to find a rectangle inside our image. I’ve tried few 320x240 bmp files and they all fail.

Here is the code:


    img = image.Image("/test.bmp", copy_to_fb=True)
    for r in img.find_rects(threshold = 10000):
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))

    print("FPS %f" % clock.fps())

And here is the error OpenMV indicates: as seen in attached “Memory error.png”

  1. Is there any ways to increase the buffer size or stack? If not, are there any other ways to get around this issue? 320x240 image is pretty small already and I can’t downsize it anymore.

  2. I also tried to use framebuf module to resize/manipulate the buffer. But the import fails, as seen in attached “Import error.png”
    Here is the document we’ve followed: framebuf — frame buffer manipulation — MicroPython 1.13 documentation

import framebuf

Thanks for help.
Memory error.png

Import error.png

Hi, the algorithm runs on a max resolution of 160x120 pixels. Please keep inind our system is a microcontroller with limited RAM. Find_rects() is based on the quad finder that powers April Tags. It needs about 16x the resolution of RAM to process the image. So, at 160x120 it needs over 300k of RAM. Our frame buffer is about 384kb. So, 160x120 is the largest res that fits. For 320x240 we’d need several megabytes which we don’t have.

Please downsample the image to 160x120. Unless there’s an obvious loss of detail on lines in the image downsampling it more is fine.

As for the framebuf module. We don’t support that MicroPython module since it’s for the pyboard only.

Thanks for your help!

Where can I tweak the frame buffer size in the configuration? Or it is fixed to be 384kb.

Its at the max size it can possibly be. 160x120 is really the useful limit. That said, with the latest firmware you can do about 200x200 pixels at the absolute max.