Monday 30 November 2020

Raspberry Pi Camera Images - I made a mistake!

When I set-up the Raspberry Pi camera to take pictures every 2 minutes (see my previous post), I did not check up on the files to see if they were saving properly. My goal was to leave the Pi running for at-least 10 days to get a large amount of images to work on some image processing and convolutional neural networks.

When I did my initial test for 1 days I calculated my image file size to be very small (max of about 200kB). So, if there a photo every 2 minutes, that's about 720 photos a day and 7200 photos in 10 days. Which is only 1.4-1.5GB of space - not a problem. Since my Raspberry Pi zero was did not come with WiFi I didn't bother looking at the progress as I didn't want to disturb the camera.

So where did I go wrong? When I did my first test I had a small Python script which took a photo every 5 minutes, but since the python script tends to leave the camera on as long as it is running, I decided to write a small shell script which can also do the same thing and I scheduled the script from Crontab to run every 2 minutes, but I did not check on the new file size. Apparently running the camera this way actually saves an Image of roughly 2.5MB instead of 200kB - Oops. The rest is simple, my Raspberry Pi exceeded by initial estimates by the end of Day 1 and the file system crashed at the end of Day 2. However, I did manage to extract the files from the SD card.

But turns out this is not the reason why my file system crashed. At the end of day 2 I only had about 2.5GB of space on an 8GB SD card. I knew there was no way my files could have exceeded this limit. So why then? When I did some reading I realized that this was to do with the block size. The block size on my Raspbian OS is about 4096 bytes, which means that any file is saved on fixed blocks of 4MB. Whether my image was 200kB or 2.5MB it would have taken up 4MB to save the file. So, looking at it this way it can be easily seen that to save my 2 days worth of images it had actually taken close to 5GB of disk space.

So technically, this attempt would have been a bust either way. Time to look in to a new method of saving files.

No comments:

Post a Comment