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
-
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
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 -
@itcandowhat Instead of implementing new code you can try standard example which you can find here:
Or you can implement code from here
I hope you can use images stored in your SD card and stich using FFMPEG.
-
@anshumanfauzdar
Hi AnshI'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.
-
@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