The right way to save image to external SD card


I am writing a program to capture object by OpenMV camera. After the object is detected, I use to save image into external SD card. After I remount the OpenMV storage, I found the image is corrupted (refer to the attached file).

I wonder what the right approach to save the image file is. I.e. what should I do after executing the .save() method?

I also tried to add time.sleep(1) for the buffer flushing but it didn’t work.



I checked my code carefully and finally found the reason!

It is incorrectly use sensor.dealloc_extra_fb() to deallocate the memory before saving the image to file, which caused some memory are overwritten but still being saved to file.

It is not the file corrupted but the content is.