Consuming Time issue of saving Image to SD card

Hi there.
When I try saving multi images into SD card in a while loop like:

while True:
    img = sensor.snapshot().compress(50)

Problem is: the time usage of increases as the process goes on.
That for example,
when script starts running and saving the first dozens of images, needs 40-50 ms/image, but as more images been saved into SD Card, time usage of can slowly rise up from 50ms to 100+ms.

I can’t figure out why, Any help would be grateful.

It’s because you fill the directory up with images. The save() method has to find free space in the directory to save the image to which requires a scan of the directory in FAT. This costs time as it’s done 32-bytes at a time doing string compares.

If you want faster image saving using the ImageWriter format which makes one big file.

Also please make sure you’re using exFAT and Not FAT.

ok, I will test the gap of performances in both methods. As your proposed method ImageWriter() I can get one big file images.bin, there are some questions about it:

I want to read and process the saved images in PC, In other words, in PC, how can I convert .bin to Image Format like cv2::Mat or numpy.narray() or something that I can handle as images one by one?

Appreciate your kind reply.

Use the IDE video tools to convert the generated .bin file to a list of JPEG images. You can pass the output to be “%.jpg” and then the file will be split up into jpegs. One per frame. So, it may be a ton. Same for “%.png”

Thanks! for reply!
Following you instruction, I took several tests and would like share my result to those guys needed.

1 ImageWriter method to record uncompressed video

I test the example, the API is named image.ImageIO(’/path’, ‘w’) in this example, not image.ImageWriter(’/path’, ‘w’) which can not work, I think image.ImageIO() method is what you mean too to get .bin file.
to deal with the .bin file in PC, we can use OpenMV IDE, or the the following python script:

#!/usr/bin/env python2.7
import cv2
import numpy as np

file = open("WVGA2.bin", "rb") 
index = 1
while True:
    img_byte = + 752*480) # in case the resolution is 752x480
    img_np = np.fromstring(img_byte, dtype='uint8')
    image = img_np[16:].reshape(480,752)
    print (index)
    index = index + 1

2 mjpeg.Mjpeg() method to record compressed video

seen in example
as a compressed format, the speed of recording is a little bit faster than uncompressed format, while if someone want to read .mjpeg in PC, you can try this one:

 #!/usr/bin/env python2.7
import cv2
import numpy as np

camera = cv2.VideoCapture('example.mjpeg')
index = 1
    print (index)
    index = index + 1
    retval, im =
    if not retval:
    cv2.imshow("image", im)
    k = cv2.waitKey(1) 

Hi, Thanks for hints.
I actually used FAT before I issued this post, I checked the difference between exFAT and FAT, but I can not figure out why exFAT is suggested. So,

what is the reason to prefer exFAT?
is it a must in some cases?

Also, I did reformat the SD card to exFAT as you suggested, but little difference appears after that in my case. I don’t know whether I miss some thing. So would you please specify my doubt?

Great thanks.

Hi, I’m the next firmware release this will all run much faster. We have true double/triple buffering working now which allows the camera to capture frames while writing them to the disk.