Re: ESP32 CAM direct access to image data
Posted: Sat Jun 15, 2019 10:04 am
Anyone?
From:XenonXenon wrote: βWed Jun 12, 2019 2:38 pmBut I cannot find the code for dl_matrix3du_alloc anywhere and whilst the calling context makes clear that parameters 2 & 3 are width & height I do not know what parms 1 & 4 are.
Code: Select all
...
/*
* @brief Allocate a 3D matrix with 8-bits items, the access sequence is NHWC
*
* @param n Number of matrix3d, for filters it is out channels, for others it is 1
* @param w Width of matrix3d
* @param h Height of matrix3d
* @param c Channel of matrix3d
* @return 3d matrix
*/
dl_matrix3du_t *dl_matrix3du_alloc(int n, int w, int h, int c);
...
Code: Select all
...
fb = esp_camera_fb_get();
...
s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf);
...
Code: Select all
...
/**
* @brief Convert image buffer to RGB888 buffer (used for face detection)
*
* @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
* @param src_len Length in bytes of the source buffer
* @param format Format of the source image
* @param rgb_buf Pointer to the output buffer (width * height * 3)
*
* @return true on success
*/
bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
...
Code: Select all
uint8_t *out_buf = (uint8_t*)ps_malloc(out_len);
fmt2rgb888(fb->buf, fb->len, fb->format, out_buf);
esp_camera_fb_return(fb);
...
free(out_buf);
Code: Select all
// Access the data as a series of uint8_t
uint8_t *StartOfFrameBufferAsSequenceOfBytes = (uint8_t *)FrameBuffer->buf;
size_t NumberOfBytesInFrameBuffer = FrameBuffer->len;
size_t NumberOfImageRows = 1200;
size_t NumberOfImagePixelsPerRow = 1600;
size_t NumberOfBytesPerPixel = 3;
// (width * height * bytes per pixel)
// In other words it's a sequence of Image Rows (scanlines), top to bottom.
// Each Image Row consists of a sequence of Pixels, left to right.
// Each Pixel consists of 3 bytes, one each for Red, Blue, and Green.
// TRY writing a RED line of pixels every tenth row.
uint8_t *StartOfRowInFrameBufferAsSequenceOfBytes;
uint8_t *StartOfCurrentPixelInRow;
uint8_t *CurrentPixelInRow;
for (size_t RowNumber = 0 ; RowNumber < 1 /*NumberOfImageRows */ ; RowNumber += 10)
{
StartOfRowInFrameBufferAsSequenceOfBytes = StartOfFrameBufferAsSequenceOfBytes + (RowNumber * NumberOfImagePixelsPerRow * NumberOfBytesPerPixel);
StartOfCurrentPixelInRow = StartOfRowInFrameBufferAsSequenceOfBytes;
for (size_t PixelCounter = 0; PixelCounter < NumberOfImagePixelsPerRow ; ++PixelCounter , StartOfCurrentPixelInRow += NumberOfBytesPerPixel)
{
CurrentPixelInRow = StartOfCurrentPixelInRow;
uint8_t ExistingByte = *CurrentPixelInRow;
*CurrentPixelInRow = 255;
++CurrentPixelInRow;
*CurrentPixelInRow = 0;
++CurrentPixelInRow;
*CurrentPixelInRow = 0;
}
}
Code: Select all
config.pixel_format = PIXFORMAT_JPEG;
if(psramFound())
{
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10 ; // RCG initially 10; //0-63 lower number means higher quality
config.fb_count = 2;
}
else
{
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 12 ; // RCG initially 12;//0-63 lower number means higher quality
config.fb_count = 1;
}
esp_err_t err = esp_camera_init(&config);
Code: Select all
s->pixformat = PIXFORMAT_RGB888;
camera_fb_t * FrameBuffer = esp_camera_fb_get();
Code: Select all
s->pixformat = PIXFORMAT_RGB888;
Code: Select all
s->pixformat = PIXFORMAT_RGB888;
Code: Select all
s->pixformat = PIXFORMAT_RGB888;
Code: Select all
sensor_t * s = esp_camera_sensor_get();
Code: Select all
s->pixformat = PIXFORMAT_JPEG;
Code: Select all
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = InitialFrameSize; // originally FRAMESIZE_UXGA;
esp_err_t err = esp_camera_init(&config);
Code: Select all
sensor_t * s = esp_camera_sensor_get();
s->pixformat = PIXFORMAT_RGB888;
s->set_framesize(s, FRAMESIZE_VGA);
camera_fb_t * FrameBuffer = esp_camera_fb_get();
Code: Select all
s->pixformat = PIXFORMAT_RGB888;