Corruption in image loading

Hi,
I’m facing a very strange behavior after loading an image through OpenMV. For some unknown reason, the image loads correctly in the IDE interface, but the values in the framebuffer appear to be corrupted (colons of pixels are shifted) in memory. I can confirm this issue by simply saving the exact same file after the initial load.

Using a very basic script, I can reliably reproduce the bug.
Does anyone know how to fix this issue?

Below is the minimal code example I used to reproduce the behavior:

   # CODE
mask = sensor.alloc_extra_fb(64, 64, sensor.GRAYSCALE)
mask.replace(image.Image(“bag_mask.png”, copy_to_fb=True))
print(mask.width() , mask.height(),“GRAYSCALE =”,mask.format()==image.GRAYSCALE)
mask.save(“bag_mask_openMV.png”)


Initial loaded picture

bag_mask

Resulted saved picture :

bag_mask_openMV

Hi, that’s a bug in the png file save code. Can you use bmp or jpg format instead? The png code is lightly tested. Also, please make a bug on github for us to fix after the next release.

Thanks for the quick support. It works with both PGM and BMP files, but it fails with JPG for another reason. The issue is mainly from the loading of the file and not the saving, as I can also see the bit-shifted pattern when using this mask for basic operations (b_and(), b_or(), clear(), mean(), etc.).

I will open a bug report on GitHub and close this topic.
Thank you.

Hi, what’s the reason it fails for jpg? JPG should be well debugged and solid.

With JPEG, I initially thought the issue was due to the format not being fully supported, so I didn’t spend additional time investigating as switching to PGM solved the problem.
The error I was getting was: OSError: Non-Baseline JPEGs are not supported.

Hi, that’s an issue with the jpeg itself. You can probably fix that by creating it using a different program.

1 Like

thanks