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 Arduino Edge Impulse Camera
-
Anyone here a Spresense camera expert. I just got my Spresense going on the Arduino IDE yesterday and would like to convert this Arduino Portenta TinyML EdgeImpulse code here that took months to write to work with the Spresense camera.
Anyone fairly good with the camera that I can bounce questions off?
Not planning on spending much time with the Spresense because I already have a curriculum to work on, but if I can get it working I will include a few videos in my EdgeImpulse Machine Learning playlist here
-
Hi Jeremy, the code to work with the Spresense camera is straight forward, once you have an image you can resize it the way you want by calling the resizeByHardware function, quite fast, done by hardware.
// THE HEADER
#include <Camera.h>// THIS IS TO SET THE OPTIONS YOU WANT AND START THE CAMERA
CamErr cameraStatus;
cameraStatus= theCamera.begin();if ( cameraStatus != CAM_ERR_SUCCESS )
{
// YOUR ERROR HANDLER
}// STARTS STREAMING (The Callback will be invoked)
cameraStatus= theCamera.startStreaming( true, CamCallBack );
if ( cameraStatus != CAM_ERR_SUCCESS )
{
// YOUR ERROR HANDLING
}cameraStatus= theCamera.setAutoWhiteBalanceMode( CAM_WHITE_BALANCE_DAYLIGHT);
if ( cameraStatus != CAM_ERR_SUCCESS )
{
// YOUR ERROR HANDLING
}// SET THE FORMATS YOU WANT, YUV IS EASIER TO HANDLE
cameraStatus= theCamera.setStillPictureImageFormat( CAM_IMGSIZE_QUADVGA_H, CAM_IMGSIZE_QUADVGA_V, CAM_IMAGE_PIX_FMT_JPG);
if ( cameraStatus != CAM_ERR_SUCCESS )
{
// YOUR ERROR HANDLING
}cameraStatus= theCamera.setColorEffect( CAM_COLOR_FX_BW );
if ( cameraStatus != CAM_ERR_SUCCESS )
{
)// THIS IS THE CALLBACK F. USED FOR PREVIEW,
// YOU CAN GET THE BUFFER TO HANDLE THE PIXELS
// getImgBuff() is the method name, again YUV makes
// things easiervoid CamCallBack( CamImage sample )
{
if (sample.isAvailable())
{}
return;
}// THIS IS THE METHOD TO TAKE THE PICTURE IF YOU
// DON'T WANT TO DO IT IN THE PREVIEW CALLBACKCamImage sampleImage= theCamera.takePicture();
-
(I saw you used RGB on your code, you can set that format on the Spresense as well)
-
Actually doing OK. Thanks @CGM11 The camera takes nice pictures in MPG format at converts them to RGB565 format. That is going fine. Seems like I can convert the camera img to these frame_buffer formats.
uint16_t frame_buffer[320 * 240] = { 0 }; // or uint8_t frame_buffer[320*240] __attribute__((aligned(32)));
which something like this seems to work.
memcpy(frame_buffer, img.getImgBuff, sizeof(img.getImgBuff));
but presently the Edge Impulse Arduino code is not compiling. Which also happens with sound files, so I think it is some other issue, probably similar to the windows platform.local.txt file issue. I will research it.
-
@hpssjellis Great Jeremy, depending on the format you choose in the first place, you can convert image formats as you want, I like YUV because you have two bytes, one for the pixel and the other one for the color, that is handy.
Did you generate the edge impulse library these days ? it is supposed they are now allowing you to deploy Spresense libraries, I couldn't test it yet but the Spresense picture is there! I was having troubles a few month ago, something like namespaces confusions... or something.
Keep going.
-
By the way, you have a img.getImgSize() method, there is no need to use sizeof. More conversions can be performed to the image by using this method:
img.convertPixFormat( CAM_IMAGE_PIX_FMT_GRAY );
Have fun!