Memory Allocation Failed Error


I am trying to get pixels of a grayscale image and save it to my array, but I am having memory allocation failed error as you can see in the picture. Why? Sorry for asking a dumb question, I am new to both OpenMV cam and Python.

You’re just running out of memory, the camera doesn’t have a lot of memory, the heap is only ~230KBs, there’s no fix for this. I’m not sure why you’re making a copy of the image, but if you must, try setting a smaller resolution/window.


Thank you for your fast answer. I am trying to calculate the trash level in the trash bin. So, I am trying to get amount of non-black pixels (because trash bin has a black trash bin inside) in the image to all four sides starting from the center. I added a visual for better understanding.

So, I am trying to calculate x1,x2,y1, and y2 levels by subtracting black parts of the image. Any ideas how can I do this in camera? I implemented same stuff on MATLAB but its a different thing of course.

You can use find_blobs and search for a black (or white) blob, then call blob.pixels() to get the number of pixels in that blob, you may also want to check the get_statistics function.

Again thank you for your answer. One more question, is it possible to use background subtraction method in this case? Is OpenMV H7 able for background sub?

Yes you can subtract a background image, see the examples.