⚡ app_camera_init, app_camera_decode
parent
eb323fbb7c
commit
e913d228c9
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
static const char *TAG = "app_camera";
|
static const char *TAG = "app_camera";
|
||||||
|
|
||||||
void app_camera_init(framesize_t frame_size, uint8_t jpeg_quality, uint8_t fb_count)
|
void app_camera_init(const pixformat_t pixel_fromat, const framesize_t frame_size, const uint8_t fb_count, const uint8_t jpeg_quality)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Camera module is %s", CAMERA_MODULE_NAME);
|
ESP_LOGI(TAG, "Camera module is %s", CAMERA_MODULE_NAME);
|
||||||
|
|
||||||
|
@ -47,30 +47,7 @@ void app_camera_init(framesize_t frame_size, uint8_t jpeg_quality, uint8_t fb_co
|
||||||
config.pin_pwdn = CAMERA_PIN_PWDN;
|
config.pin_pwdn = CAMERA_PIN_PWDN;
|
||||||
config.pin_reset = CAMERA_PIN_RESET;
|
config.pin_reset = CAMERA_PIN_RESET;
|
||||||
config.xclk_freq_hz = XCLK_FREQ_HZ;
|
config.xclk_freq_hz = XCLK_FREQ_HZ;
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
config.pixel_format = pixel_fromat;
|
||||||
config.pixel_format = PIXFORMAT_RGB565;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_YUV422
|
|
||||||
config.pixel_format = PIXFORMAT_YUV422;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_GRAYSCALE
|
|
||||||
config.pixel_format = PIXFORMAT_GRAYSCALE;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_JPEG
|
|
||||||
config.pixel_format = PIXFORMAT_JPEG;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB888
|
|
||||||
config.pixel_format = PIXFORMAT_RGB888;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RAW
|
|
||||||
config.pixel_format = PIXFORMAT_RAW;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB444
|
|
||||||
config.pixel_format = PIXFORMAT_RGB444;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB555
|
|
||||||
config.pixel_format = PIXFORMAT_RGB555;
|
|
||||||
#endif
|
|
||||||
config.frame_size = frame_size;
|
config.frame_size = frame_size;
|
||||||
config.jpeg_quality = jpeg_quality;
|
config.jpeg_quality = jpeg_quality;
|
||||||
config.fb_count = fb_count;
|
config.fb_count = fb_count;
|
||||||
|
@ -94,27 +71,31 @@ void app_camera_init(framesize_t frame_size, uint8_t jpeg_quality, uint8_t fb_co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_camera_decode(camera_fb_t *fb, uint16_t **image_ptr)
|
void *app_camera_decode(camera_fb_t *fb)
|
||||||
{
|
{
|
||||||
assert(fb->format == PIXFORMAT_RGB565);
|
if (fb->format == PIXFORMAT_RGB565)
|
||||||
*image_ptr = (uint16_t *)fb->buf;
|
{
|
||||||
return true;
|
return (void *)fb->buf;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
bool app_camera_decode(camera_fb_t *fb, uint8_t **image_ptr)
|
|
||||||
{
|
{
|
||||||
*image_ptr = (uint8_t *)dl::tool::malloc_aligned(fb->height * fb->width * 3, sizeof(uint8_t));
|
uint8_t *image_ptr = (uint8_t *)malloc(fb->height * fb->width * 3 * sizeof(uint8_t));
|
||||||
if (!*image_ptr)
|
if (image_ptr)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "malloc memory for image rgb888 failed");
|
if (fmt2rgb888(fb->buf, fb->len, fb->format, image_ptr))
|
||||||
return false;
|
{
|
||||||
|
return (void *)image_ptr;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (!fmt2rgb888(fb->buf, fb->len, fb->format, *image_ptr))
|
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "fmt2rgb888 failed");
|
ESP_LOGE(TAG, "fmt2rgb888 failed");
|
||||||
dl::tool::free_aligned(*image_ptr);
|
dl::tool::free_aligned(image_ptr);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "malloc memory for image rgb888 failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,15 @@
|
||||||
/**
|
/**
|
||||||
* @brief Initialize camera
|
* @brief Initialize camera
|
||||||
*
|
*
|
||||||
|
* @param pixformat One of
|
||||||
|
* - PIXFORMAT_RGB565
|
||||||
|
* - PIXFORMAT_YUV422
|
||||||
|
* - PIXFORMAT_GRAYSC
|
||||||
|
* - PIXFORMAT_JPEG
|
||||||
|
* - PIXFORMAT_RGB888
|
||||||
|
* - PIXFORMAT_RAW
|
||||||
|
* - PIXFORMAT_RGB444
|
||||||
|
* - PIXFORMAT_RGB555
|
||||||
* @param frame_size One of
|
* @param frame_size One of
|
||||||
* - FRAMESIZE_96X96, // 96x96
|
* - FRAMESIZE_96X96, // 96x96
|
||||||
* - FRAMESIZE_QQVGA, // 160x120
|
* - FRAMESIZE_QQVGA, // 160x120
|
||||||
|
@ -29,27 +38,16 @@
|
||||||
* - FRAMESIZE_WQXGA, // 2560x1600
|
* - FRAMESIZE_WQXGA, // 2560x1600
|
||||||
* - FRAMESIZE_P_FHD, // 1080x1920
|
* - FRAMESIZE_P_FHD, // 1080x1920
|
||||||
* - FRAMESIZE_QSXGA, // 2560x1920
|
* - FRAMESIZE_QSXGA, // 2560x1920
|
||||||
* @param jpeg_quality Quality of JPEG output. 0-63 lower means higher quality
|
|
||||||
* @param fb_count Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed)
|
* @param fb_count Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed)
|
||||||
|
* @param jpeg_quality Quality of JPEG output. 0-63 lower means higher quality
|
||||||
*/
|
*/
|
||||||
void app_camera_init(framesize_t frame_size, uint8_t jpeg_quality, uint8_t fb_count);
|
void app_camera_init(const pixformat_t pixel_fromat, const framesize_t frame_size, const uint8_t fb_count, const uint8_t jpeg_quality = 12);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Decode fb into RGB565
|
* @brief Decode fb ,
|
||||||
|
* - if fb->format == PIXFORMAT_RGB565, then return fb->buf
|
||||||
|
* - else, then return a new memory with RGB888, don't forget to free it
|
||||||
*
|
*
|
||||||
* @param fb
|
* @param fb
|
||||||
* @param image_ptr
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
*/
|
||||||
bool app_camera_decode(camera_fb_t *fb, uint16_t **image_ptr);
|
void *app_camera_decode(camera_fb_t *fb);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Decode fb into RGB888
|
|
||||||
*
|
|
||||||
* @param fb
|
|
||||||
* @param image_ptr
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
bool app_camera_decode(camera_fb_t *fb, uint8_t **image_ptr);
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "esp_camera.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
||||||
|
@ -181,3 +182,28 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define XCLK_FREQ_HZ 20000000
|
#define XCLK_FREQ_HZ 20000000
|
||||||
|
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_RGB565
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_YUV422
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_YUV422
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_GRAYSCALE
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_GRAYSCALE
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_JPEG
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_JPEG
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB888
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_RGB888
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RAW
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_RAW
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB444
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_RGB444
|
||||||
|
#endif
|
||||||
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB555
|
||||||
|
#define CAMERA_PIXEL_FORMAT PIXFORMAT_RGB555
|
||||||
|
#endif
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
extern "C" void app_main()
|
extern "C" void app_main()
|
||||||
{
|
{
|
||||||
app_camera_init(FRAMESIZE_QVGA, 12, 2);
|
app_camera_init(CAMERA_PIXEL_FORMAT, FRAMESIZE_QVGA, 2);
|
||||||
app_dl_init();
|
app_dl_init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ extern "C" void app_main()
|
||||||
app_wifi_main();
|
app_wifi_main();
|
||||||
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
||||||
app_camera_init(FRAMESIZE_QVGA, 12, 2);
|
app_camera_init(CAMERA_PIXEL_FORMAT, FRAMESIZE_QVGA, 2);
|
||||||
#else
|
#else
|
||||||
app_camera_init(FRAMESIZE_UXGA, 12, 2);
|
app_camera_init(CAMERA_PIXEL_FORMAT, FRAMESIZE_UXGA, 2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_LED_ILLUMINATOR_ENABLED
|
#if CONFIG_LED_ILLUMINATOR_ENABLED
|
||||||
|
|
Loading…
Reference in New Issue