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.
Resize image taken by camera
-
Hi,
I'm having problems to take a small size image with the spresense (120x120).
I'm calling to setStillPictureImageFormat with a size of 120 x 120, when images are simple (with not too much changes on the colours or objects) it works, but when I try to take more complex photos (like a street with cars and people), it fails and don't know why (I suppose the size in kB of the file is bigger and some buffer is going out of size, but not sure what is the camera library doing).When the size is 320x240 it always works. So, can I take a photo of 320x240 and then resize it to 120x120?
Which is the way to do it?
CamImage Image; Image = theCamera.takePicture(); /* RESIZE IT. Should I use resizeImageByHW() ?¿?¿ */ /* How to use it, resizeImageByHW(Image,120,120) ?¿ */ return(Image);
-
I have also read this note in the Camera Library from the Developer Guide. I've tried to decrease that value, but it works in the same way.
If the acquisition of CamImage fails in JPEG cases, it is possible that the capacity of the JPEG buffer size set by setStillPictureImageFormat () is insufficient. You can increase the JPEG buffer size by reducing the value of the function parameter jpgbufsize_divisor. Also, if the overall memory capacity is insufficient and the buffer size cannot be obtained, it may be possible to solve it by expanding the memory used by the MainCore application. See Arduino memory size configuration for more information.
-
When you say low values, did you try to set the jpgbufsize_divisor to 1?
It seems like compression ratio for JPEG for very small images is not so good.err = theCamera.setStillPictureImageFormat(120, 120, CAM_IMAGE_PIX_FMT_JPG, 1);
What is your JPEG quality?
theCamera.setJPEGQuality(80);
Can you check how much memory you have available?
#include "Arduino.h" void printFreeMemory() { int fd; std::vector<char> buf(128); fd = open(CONFIG_NSH_PROC_MOUNTPOINT "/meminfo", O_RDONLY); if (fd < 0) { return; } while (true) { memset(buf.data(), 0, buf.size()); int nbytesread = read(fd, (void*)buf.data(), buf.size() - 1); if (nbytesread <= 0) { break; } else { Serial.write((char*)buf.data()); } } close(fd); }
Do you check the return values of e.g. setStillPictureImageFormat?
Sorry I did not try (yet) this resolution myself. Maybe adding some prints inside the Camera Library can determine what goes wrong.
-
Also, did you check this part of the documentation:
https://developer.sony.com/develop/spresense/docs/arduino_developer_guide_en.html#_to_convert_imageIt talks about the resizeImageByHW() and clipAndResizeImageByHW() functions.