Question about Raspberry Pi SPI Camera Demo JPEG Capture Size

Hello,

I am using the Arducam mini 2mp plus SPI camera.

I’m using the demo code from github (https://github.com/ArduCAM/RaspberryPi/tree/master/SPI_Camera) to start capturing images.

I use the singleCapture function and then write the buffer directly to a file (snippet included at the bottom).

Is this the correct approach? The file size is ~16MB with the resolution being the default 320x240.

singleCapture(CAM_CS1);

sendbuf_cam1 = readbuf;
length_cam1 = length;

char image_file[] = “capture.jpg”;

FILE *fp;
fp = fopen(image_file, “w”);

int i = 0;

for(i = 0; i < length_cam1; i++){
fwrite(sendbuf_cam1, sizeof(char), length_cam1, fp);
}

fclose(fp);

 

I realized this question was a bit vague. The image file is created correctly and I can view it on my computer.

My specific concern is that the file is quite large given the resolution.

Is there a way to reduce the size of the file? Should I be writing the whole sendbuf_cam1 buffer to file?

Hi,

Why the image is so big? it is error. As normal, for 2mp for 320x240 resolution in jpeg format.

the size is about 3-4kb. You can try to print the data of the buffer to the terminal.

For the jpeg image the header is 0xFF 0xD8 and the end is 0xFF and 0xD9

Thank you.

Turns out I was making a silly error and writing the full image data multiple (thousands) of times.

Great to hear you have find the problem. Let me know if you need more help.