Memory Error, out of fast Frame Buffer Stack

Discussion related to "under the hood" OpenMV topics.
fantasy2019
Posts: 2
Joined: Tue Dec 04, 2018 9:58 pm

Memory Error, out of fast Frame Buffer Stack

Postby fantasy2019 » Tue Dec 04, 2018 10:12 pm

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:

Code: Select all

while(True):
    clock.tick()

    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(r)

    print("FPS %f" % clock.fps())
    time.sleep(1000)
And here is the error OpenMV indicates: as seen in attached "Memory error.png"

3. 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.

4. 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: https://docs.openmv.io/library/framebuf.html

Code: Select all

import framebuf
Thanks for help.
Attachments
test.jpg
Used bmp file in jpg format. As this attachment function does not support bmp upload.
Memory error.png
Memory error
Import error.png
Import error
Import error.png (22.6 KiB) Viewed 583 times
User avatar
kwagyeman
Posts: 2606
Joined: Sun May 24, 2015 2:10 pm

Re: Memory Error, out of fast Frame Buffer Stack

Postby kwagyeman » Wed Dec 05, 2018 2:26 am

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.
Nyamekye,
fantasy2019
Posts: 2
Joined: Tue Dec 04, 2018 9:58 pm

Re: Memory Error, out of fast Frame Buffer Stack

Postby fantasy2019 » Wed Dec 05, 2018 9:26 am

Thanks for your help!

Where can I tweak the frame buffer size in the configuration? Or it is fixed to be 384kb.
User avatar
kwagyeman
Posts: 2606
Joined: Sun May 24, 2015 2:10 pm

Re: Memory Error, out of fast Frame Buffer Stack

Postby kwagyeman » Wed Dec 05, 2018 12:10 pm

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.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 4 guests