MemoryError: Memory allocation failed, allocating 1024 bytes

Discussion related to "under the hood" OpenMV topics.
User avatar
garivetm
Posts: 19
Joined: Mon Sep 18, 2017 8:51 am

MemoryError: Memory allocation failed, allocating 1024 bytes

Postby garivetm » Mon Sep 18, 2017 9:09 am

Hi,

I'm using an openMV M7 to track a line using color detection. So basically, i'm setting the camera, all my com stuff and calling :

Code: Select all

img = sensor.snapshot()
My application crashes sometimes with a pop-up indicated only "MemoryError: Memory allocation failed, allocating 1024 bytes" when calling this line that evaluates the current luminosity :

Code: Select all

gs_mean = img.get_histogram(roi=roi_bottom).get_statistics().mean()
I was wondering the memory capabilities of the board, could anyone tell me more about this subject ? How much RAM is available ? How big is the frame buffer ?

thanks !
User avatar
kwagyeman
Posts: 4130
Joined: Sun May 24, 2015 2:10 pm

Re: MemoryError: Memory allocation failed, allocating 1024 bytes

Postby kwagyeman » Mon Sep 18, 2017 11:27 am

Hi, this is an error with the MicroPython Heap. Get histogram returns a rather large array of numbers which you throw away. But, those numbers have to be put on the heap in a linear array of floats. There are 3 arrays of 1024B each. So, it can be hard to fit them all sometimes once the heap gets fragmented.

Note that you can call get_statistics() directly on the image. Do that to avoid the get_histogram call. This shouldn't fail then. get_statistics will also support the ROI argument.
Nyamekye,
User avatar
kwagyeman
Posts: 4130
Joined: Sun May 24, 2015 2:10 pm

Re: MemoryError: Memory allocation failed, allocating 1024 bytes

Postby kwagyeman » Mon Sep 18, 2017 11:29 am

Please see the M7 product page for the RAM under the specs tab.

Also, you can pass a parameter to get histogram to reduce the number of bins if you are still having issues. This will reduce the RAM requirement.
Nyamekye,
User avatar
garivetm
Posts: 19
Joined: Mon Sep 18, 2017 8:51 am

Re: MemoryError: Memory allocation failed, allocating 1024 bytes

Postby garivetm » Tue Sep 19, 2017 4:50 am

I really appreciate your answer thank you.

To people looking for the RAM specs, here is what is mentioned in the CAM M7 datasheet (RAM Layout) :
- 128KB .DATA/.BSS/Heap/Stack
- 384KB Frame Buffer/Stack
(512KB Total)
kwagyeman wrote: Note that you can call get_statistics() directly on the image. Do that to avoid the get_histogram call. This shouldn't fail then. get_statistics will also support the ROI argument.
OK I will definitively use get_statistics() directly on an image.
I'll come back to you if I encounter any problem.

Best regards,
MG.
User avatar
iabdalkader
Posts: 1180
Joined: Sun May 24, 2015 3:53 pm

Re: MemoryError: Memory allocation failed, allocating 1024 bytes

Postby iabdalkader » Sat Sep 23, 2017 8:38 pm

garivetm wrote:
Tue Sep 19, 2017 4:50 am
To people looking for the RAM specs, here is what is mentioned in the CAM M7 datasheet (RAM Layout) :
- 128KB .DATA/.BSS/Heap/Stack
- 384KB Frame Buffer/Stack
(512KB Total)
Note there's also a 128KBs Tightly Coupled Memory (TCM) memory that we're also using. Also That's not the actual memory layout we're using, it depends on the cam. For M7 the data, bss, heap and stack sections (as well as some buffers) are placed in the TCM. The framebuffer and some memory allocator use the main SRAM.

Edit: you mentioned the 128KBs already.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests