Sony's Developer World forum

    • Home
    • Forum guidelines

    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.

     

     

    Accessing image buffer for preview image

    Spresense
    arduinoide camera
    2
    4
    606
    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
      itcandowhat last edited by

      Hi
      I've been trying to get the preview feed from the spresense camera using the Arduino IDE , but get garbage data using img.getImgBuff().

      Here's the code I repurposed from one of the camera examples

      #include <SDHCI.h>
      #include <stdio.h>  /* for sprintf */
      #include <Camera.h>
      #define BAUDRATE                (115200)
      SDClass  theSD;
      int take_picture_count = 0;
      int imgbuffer[153600];
      int i;
      void CamCB(CamImage img) {
      
        if(img.isAvailable() == false) {
          return;
        }
        img.convertPixFormat(CAM_IMAGE_PIX_FMT_RGB565);
        uint16_t *b;
        char *preview = img.getImgBuff();
        size_t x = img.getImgBuffSize();
        int w = img.getWidth();
        int h = img.getHeight();
        for (i=0;i < img.getImgSize(); ++i, ++preview) {
          Serial.print(*preview);
        }
        Serial.print(x);
        Serial.print(",");
         Serial.print(w);
        Serial.print(",");
         Serial.print(h);
        Serial.print(",");
        Serial.println("done");
      }
      
      void setup()
      {
      
        /* Open serial communications and wait for port to open */
      
        Serial.begin(BAUDRATE);
        /* Initialize SD */
        while (!theSD.begin()) 
          {
            /* wait until SD card is mounted. */
            Serial.println("Insert SD card.");
          }
        Serial.println("Prepare camera");
        theCamera.begin(1, CAM_VIDEO_FPS_30, CAM_IMGSIZE_QVGA_H, CAM_IMGSIZE_QVGA_V, 
        CAM_IMAGE_PIX_FMT_YUV422);
      
          
      theCamera.startStreaming(true, CamCB);
       //Serial.println("Set Auto white balance parameter");
      theCamera.setAutoWhiteBalanceMode(CAM_WHITE_BALANCE_DAYLIGHT);
      
        
      }
      
      
      void loop()
      {
      }
      

      But here's my output
      728bbf6f-6aa8-4612-afff-c05a746613e1-image.png
      I want to to get the image frames so I can use ffmpeg later to stitch a video together but find myself stuck here.
      Any help will be appreciated
      Thank you

      AnshumanFauzdar 1 Reply Last reply Reply Quote
      • AnshumanFauzdar
        AnshumanFauzdar @itcandowhat last edited by

        @itcandowhat Instead of implementing new code you can try standard example which you can find here:
        2c2f7700-0d67-4cdd-b04f-ff3946073476-image.png

        Or you can implement code from here

        I hope you can use images stored in your SD card and stich using FFMPEG.

        I 1 Reply Last reply Reply Quote
        • I
          itcandowhat @AnshumanFauzdar last edited by

          @anshumanfauzdar
          Hi Ansh

          I'm actually trying to build a real-time video recording solution with the spresense package and also found some work related to it in other threads but almost all of them were plagued with poor fps.

          I need the raw stream of frames from the camera and hence tried the image buffer but get strange data from it. Is my code wrong. Or it something else.

          Please advice.

          AnshumanFauzdar 1 Reply Last reply Reply Quote
          • AnshumanFauzdar
            AnshumanFauzdar @itcandowhat last edited by

            @itcandowhat Hey, I have tried several methods and yes you will face low FPS problem.

            In your code you are implementing buffer solution, one possible problem can be data getting corrupt before writing new data or similar problem.

            You can try sending data over serial first as mentioned in this post

            There is serial live feed available in edge impulse also but again low FPS problem 😞

            Best thing you can try sending images over serial and stich in real-time but sony spresense is IoT-development board and more powerful solutions are out there for real time video recording like raspberry pi high resolution or OpenCV OAK series which are available in USB and POE connections

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