Sony's Developer World forum

    • Home
    • Forum guidelines

    Resize image taken by camera

    Spresense
    3
    4
    937
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      Inagore 0 6 6 3 1 1 last edited by

      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);
      
      C 1 Reply Last reply Reply Quote
      • I
        Inagore 0 6 6 3 1 1 last edited by

        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.
        
        J 1 Reply Last reply Reply Quote
        • J
          jens 0 1 1 @Inagore 0 6 6 3 1 1 last edited by

          @Inagore-0-6-6-3-1-1

          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.

          1 Reply Last reply Reply Quote
          • C
            CamilaSouza DeveloperWorld @Inagore 0 6 6 3 1 1 last edited by

            @Inagore-0-6-6-3-1-1

            Also, did you check this part of the documentation:
            https://developer.sony.com/develop/spresense/docs/arduino_developer_guide_en.html#_to_convert_image

            It talks about the resizeImageByHW() and clipAndResizeImageByHW() functions.

            1 Reply Last reply Reply Quote
            • First post
              Last post
            Developer World
            Copyright © 2021 Sony Group Corporation. All rights reserved.
            • Contact us
            • Legal