Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
Spresense Camera Example (Arduino Sketch) High Resolution Capture Does Not Work
-
Hi,
I am trying the "Camera" Arduino sketch for the Spresense camera and I can get images with the default values using..."takePicture()". If I change the image size values to FULLHD or any higher resolution I get "Error: No memory". Solution?It works if I use CAM_IMGSIZE_QUADVGA_x or lower.
err = theCamera.setStillPictureImageFormat( CAM_IMGSIZE_FULLHD_H, CAM_IMGSIZE_FULLHD_V, CAM_IMAGE_PIX_FMT_JPG);
Thank you for your help.
-
Hi @amendez
Could you please provide the full sketch together with your full error log?Thanks,
BR
Karl -
Here is the sketch... its exactly the example except the still picture format was changed from... CAM_IMGSIZE_QUADVGA_x to CAM_IMGSIZE_FULLHD_x.
#include <SDHCI.h> #include <stdio.h> /* for sprintf */ #include <Camera.h> #define BAUDRATE (115200) SDClass theSD; int take_picture_count = 0; /** * Print error message */ void printError(enum CamErr err) { Serial.print("Error: "); switch (err) { case CAM_ERR_NO_DEVICE: Serial.println("No Device"); break; case CAM_ERR_ILLEGAL_DEVERR: Serial.println("Illegal device error"); break; case CAM_ERR_ALREADY_INITIALIZED: Serial.println("Already initialized"); break; case CAM_ERR_NOT_INITIALIZED: Serial.println("Not initialized"); break; case CAM_ERR_NOT_STILL_INITIALIZED: Serial.println("Still picture not initialized"); break; case CAM_ERR_CANT_CREATE_THREAD: Serial.println("Failed to create thread"); break; case CAM_ERR_INVALID_PARAM: Serial.println("Invalid parameter"); break; case CAM_ERR_NO_MEMORY: Serial.println("No memory"); break; case CAM_ERR_USR_INUSED: Serial.println("Buffer already in use"); break; case CAM_ERR_NOT_PERMITTED: Serial.println("Operation not permitted"); break; default: break; } } /** * Callback from Camera library when video frame is captured. */ void CamCB(CamImage img) { /* Check the img instance is available or not. */ if (img.isAvailable()) { /* If you want RGB565 data, convert image data format to RGB565 */ img.convertPixFormat(CAM_IMAGE_PIX_FMT_RGB565); /* You can use image data directly by using getImgSize() and getImgBuff(). * for displaying image to a display, etc. */ Serial.print("Image data size = "); Serial.print(img.getImgSize(), DEC); Serial.print(" , "); Serial.print("buff addr = "); Serial.print((unsigned long)img.getImgBuff(), HEX); Serial.println(""); } else { Serial.print("Failed to get video stream image\n"); } } /** * @brief Initialize camera */ void setup() { CamErr err; /* Open serial communications and wait for port to open */ Serial.begin(BAUDRATE); while (!Serial) { ; /* wait for serial port to connect. Needed for native USB port only */ } /* begin() without parameters means that * number of buffers = 1, 30FPS, QVGA, YUV 4:2:2 format */ Serial.println("Prepare camera"); err = theCamera.begin(1, CAM_VIDEO_FPS_5, CAM_IMGSIZE_QVGA_H, CAM_IMGSIZE_QVGA_V, CAM_IMAGE_PIX_FMT_YUV422); if (err != CAM_ERR_SUCCESS) { printError(err); } /* Start video stream. * If received video stream data from camera device, * camera library call CamCB. */ Serial.println("Start streaming"); err = theCamera.startStreaming(true, CamCB); if (err != CAM_ERR_SUCCESS) { printError(err); } /* Auto white balance configuration */ Serial.println("Set Auto white balance parameter"); err = theCamera.setAutoWhiteBalanceMode(CAM_WHITE_BALANCE_DAYLIGHT); if (err != CAM_ERR_SUCCESS) { printError(err); } /* Set parameters about still picture. * In the following case, QUADVGA and JPEG. */ Serial.println("Set still picture format"); err = theCamera.setStillPictureImageFormat( CAM_IMGSIZE_FULLHD_H, CAM_IMGSIZE_FULLHD_V, CAM_IMAGE_PIX_FMT_JPG); if (err != CAM_ERR_SUCCESS) { printError(err); } } /** * @brief Take picture with format JPEG per second */ void loop() { sleep(1); /* wait for one second to take still picture. */ /* You can change the format of still picture at here also, if you want. */ /* theCamera.setStillPictureImageFormat( * CAM_IMGSIZE_HD_H, * CAM_IMGSIZE_HD_V, * CAM_IMAGE_PIX_FMT_JPG); */ /* This sample code can take 100 pictures in every one second from starting. */ if (take_picture_count < 100) { /* Take still picture. * Unlike video stream(startStreaming) , this API wait to receive image data * from camera device. */ Serial.println("call takePicture()"); CamImage img = theCamera.takePicture(); /* Check availability of the img instance. */ /* If any error was occured, the img is not available. */ if (img.isAvailable()) { /* Create file name */ char filename[16] = {0}; sprintf(filename, "PICT%03d.JPG", take_picture_count); Serial.print("Save taken picture as "); Serial.print(filename); Serial.println(""); /* Remove the old file with the same file name as new created file, * and create new file. */ theSD.remove(filename); File myFile = theSD.open(filename, FILE_WRITE); myFile.write(img.getImgBuff(), img.getImgSize()); myFile.close(); } take_picture_count++; } else { theCamera.end(); } }
The error on the Serial Monitor is as follows...
Prepare camera Start streaming Set Auto white balance parameter Set still picture format Error: No memory Image data size = 153600 , buff addr = D039FC0 Image data size = 153600 , buff addr = D039FC0 Image data size = 153600 , buff addr = D039FC0 call takePicture() ...
Thank you again for your help.
Best regards,
Adnorin -
Having the same issue - I can change it to CAM_IMGSIZE_HD_x and it runs but anything higher and it returns the No memory error.
-
- Update the Spresense Arduino library to the latest version.
a. Open Board Manager
b. Update to the latest version
-
Open the camera example in the Arduino IDE.
-
Change the image size to 5M.
-
Change Memory to 1536KB
-
Change the JPG_COMPRESS_RATIO to 9.
a. Open Camera.cpp file:
- Windows: %userprofile%\AppData\Local\Arduino15\packages\SPRESENSE\hardware\spresense\2.0.1\libraries\Camera\Camera.cpp
- Linux: ~/.arduino15/packages/SPRESENSE/hardware/spresense/2.0.1/libraries/Camera/Camera.cpp
- MacOS: ~/Library/Arduino15/packages/SPRESENSE/hardware/spresense/2.0.1/libraries/Camera/Camera.cpp
b. Change the JPG_COMPRESS_RATIO from 7 to 9:
- Upload camera sketch to Spresense.
- Update the Spresense Arduino library to the latest version.