mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 12:06:58 +03:00
Inital
This commit is contained in:
@@ -8,32 +8,9 @@
|
||||
#include "Helper.h"
|
||||
#include "CFindTemplate.h"
|
||||
|
||||
// #include "camera_define.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
#define BOARD_ESP32CAM_AITHINKER
|
||||
|
||||
/**
|
||||
* 2. Kconfig setup
|
||||
*
|
||||
* If you have a Kconfig file, copy the content from
|
||||
* https://github.com/espressif/esp32-camera/blob/master/Kconfig into it.
|
||||
* In case you haven't, copy and paste this Kconfig file inside the src directory.
|
||||
* This Kconfig file has definitions that allows more control over the camera and
|
||||
* how it will be initialized.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 3. Enable PSRAM on sdkconfig:
|
||||
*
|
||||
* CONFIG_ESP32_SPIRAM_SUPPORT=y
|
||||
*
|
||||
* More info on
|
||||
* https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/kconfig.html#config-esp32-spiram-support
|
||||
*/
|
||||
|
||||
// ================================ CODE ======================================
|
||||
|
||||
#include <esp_event_loop.h>
|
||||
#include <esp_log.h>
|
||||
@@ -47,31 +24,8 @@
|
||||
|
||||
#include "esp_camera.h"
|
||||
|
||||
// WROVER-KIT PIN Map
|
||||
#ifdef BOARD_WROVER_KIT
|
||||
|
||||
#define CAM_PIN_PWDN -1 //power down is not used
|
||||
#define CAM_PIN_RESET -1 //software reset will be performed
|
||||
#define CAM_PIN_XCLK 21
|
||||
#define CAM_PIN_SIOD 26
|
||||
#define CAM_PIN_SIOC 27
|
||||
|
||||
#define CAM_PIN_D7 35
|
||||
#define CAM_PIN_D6 34
|
||||
#define CAM_PIN_D5 39
|
||||
#define CAM_PIN_D4 36
|
||||
#define CAM_PIN_D3 19
|
||||
#define CAM_PIN_D2 18
|
||||
#define CAM_PIN_D1 5
|
||||
#define CAM_PIN_D0 4
|
||||
#define CAM_PIN_VSYNC 25
|
||||
#define CAM_PIN_HREF 23
|
||||
#define CAM_PIN_PCLK 22
|
||||
|
||||
#endif
|
||||
|
||||
// ESP32Cam (AiThinker) PIN Map
|
||||
#ifdef BOARD_ESP32CAM_AITHINKER
|
||||
|
||||
#define CAM_PIN_PWDN (gpio_num_t) 32
|
||||
#define CAM_PIN_RESET -1 //software reset will be performed
|
||||
@@ -91,8 +45,6 @@
|
||||
#define CAM_PIN_HREF 23
|
||||
#define CAM_PIN_PCLK 22
|
||||
|
||||
#endif
|
||||
|
||||
static const char *TAG = "example:take_picture";
|
||||
|
||||
static camera_config_t camera_config = {
|
||||
@@ -128,14 +80,11 @@ static camera_config_t camera_config = {
|
||||
.fb_count = 1 //if more than one, i2s runs in continuous mode. Use only with JPEG
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "driver/ledc.h"
|
||||
|
||||
CCamera Camera;
|
||||
|
||||
|
||||
#define FLASH_GPIO GPIO_NUM_4
|
||||
#define BLINK_GPIO GPIO_NUM_33
|
||||
|
||||
@@ -145,8 +94,6 @@ typedef struct {
|
||||
} jpg_chunking_t;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#define LEDC_LS_CH2_GPIO (4)
|
||||
#define LEDC_LS_CH2_CHANNEL LEDC_CHANNEL_2
|
||||
#define LEDC_LS_TIMER LEDC_TIMER_1
|
||||
@@ -172,14 +119,6 @@ void test(){
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size_t len){
|
||||
jpg_chunking_t *j = (jpg_chunking_t *)arg;
|
||||
if(!index){
|
||||
@@ -200,12 +139,102 @@ void CCamera::SetQualitySize(int qual, framesize_t resol)
|
||||
s->set_framesize(s, resol);
|
||||
ActualResolution = resol;
|
||||
ActualQuality = qual;
|
||||
|
||||
if (resol == FRAMESIZE_QVGA)
|
||||
{
|
||||
image_height = 240;
|
||||
image_width = 320;
|
||||
}
|
||||
if (resol == FRAMESIZE_VGA)
|
||||
{
|
||||
image_height = 480;
|
||||
image_width = 640;
|
||||
}
|
||||
if (resol == FRAMESIZE_SVGA)
|
||||
{
|
||||
image_height = 600;
|
||||
image_width = 800;
|
||||
}
|
||||
if (resol == FRAMESIZE_XGA)
|
||||
{
|
||||
image_height = 768;
|
||||
image_width = 1024;
|
||||
}
|
||||
if (resol == FRAMESIZE_SXGA)
|
||||
{
|
||||
image_height = 1024;
|
||||
image_width = 1280;
|
||||
}
|
||||
if (resol == FRAMESIZE_UXGA)
|
||||
{
|
||||
image_height = 1200;
|
||||
image_width = 1600;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
|
||||
{
|
||||
string ftype;
|
||||
static const int BMP_HEADER_LEN = 54; // von to_bmp.c !!!!!!!!!!!!!!!
|
||||
|
||||
LEDOnOff(true);
|
||||
|
||||
if (delay > 0)
|
||||
{
|
||||
LightOnOff(true);
|
||||
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
|
||||
vTaskDelay( xDelay );
|
||||
}
|
||||
|
||||
camera_fb_t * fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed");
|
||||
LEDOnOff(false);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
LEDOnOff(false);
|
||||
|
||||
uint8_t * buf = NULL;
|
||||
size_t buf_len = 0;
|
||||
|
||||
frame2bmp(fb, &buf, &buf_len);
|
||||
|
||||
int _len_zw = buf_len - BMP_HEADER_LEN;
|
||||
uint8_t *_buf_zeiger = buf + BMP_HEADER_LEN;
|
||||
|
||||
stbi_uc* p_target;
|
||||
stbi_uc* p_source;
|
||||
int channels = 3;
|
||||
int width = image_width;
|
||||
int height = image_height;
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
p_target = _Image->rgb_image + (channels * (y * width + x));
|
||||
p_source = _buf_zeiger + (channels * (y * width + x));
|
||||
p_target[0] = p_source[2];
|
||||
p_target[1] = p_source[1];
|
||||
p_target[2] = p_source[0];
|
||||
}
|
||||
|
||||
// _Image->CopyFromMemory(_buf_zeiger, _len_zw);
|
||||
|
||||
free(buf);
|
||||
|
||||
if (delay > 0)
|
||||
{
|
||||
LightOnOff(false);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t CCamera::CaptureToFile(std::string nm, int delay)
|
||||
{
|
||||
// nm = "/sdcard/josef_zw.bmp";
|
||||
string ftype;
|
||||
|
||||
LEDOnOff(true);
|
||||
@@ -286,15 +315,29 @@ esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay)
|
||||
size_t fb_len = 0;
|
||||
int64_t fr_start = esp_timer_get_time();
|
||||
|
||||
|
||||
LEDOnOff(true);
|
||||
|
||||
if (delay > 0)
|
||||
{
|
||||
LightOnOff(true);
|
||||
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
|
||||
vTaskDelay( xDelay );
|
||||
}
|
||||
|
||||
|
||||
fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
ESP_LOGE(TAGCAMERACLASS, "Camera capture failed");
|
||||
httpd_resp_send_500(req);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
LEDOnOff(false);
|
||||
|
||||
res = httpd_resp_set_type(req, "image/jpeg");
|
||||
if(res == ESP_OK){
|
||||
res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=capture.jpg");
|
||||
res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=raw.jpg");
|
||||
}
|
||||
|
||||
if(res == ESP_OK){
|
||||
@@ -312,6 +355,12 @@ esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay)
|
||||
int64_t fr_end = esp_timer_get_time();
|
||||
|
||||
ESP_LOGI(TAGCAMERACLASS, "JPG: %uKB %ums", (uint32_t)(fb_len/1024), (uint32_t)((fr_end - fr_start)/1000));
|
||||
|
||||
if (delay > 0)
|
||||
{
|
||||
LightOnOff(false);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -369,7 +418,7 @@ void CCamera::GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol
|
||||
if (strcmp(_size, "SXGA") == 0)
|
||||
resol = FRAMESIZE_SXGA; // 1280x1024
|
||||
if (strcmp(_size, "UXGA") == 0)
|
||||
resol = FRAMESIZE_UXGA; // 1600x1200
|
||||
resol = FRAMESIZE_UXGA; // 1600x1200
|
||||
}
|
||||
if (httpd_query_key_value(_query, "quality", _qual, 10) == ESP_OK)
|
||||
{
|
||||
@@ -409,8 +458,6 @@ CCamera::CCamera()
|
||||
|
||||
esp_err_t CCamera::InitCam()
|
||||
{
|
||||
printf("Init Flash\n");
|
||||
//power up the camera if PWDN pin is defined
|
||||
if(CAM_PIN_PWDN != -1){
|
||||
// Init the GPIO
|
||||
gpio_pad_select_gpio(CAM_PIN_PWDN);
|
||||
|
||||
Reference in New Issue
Block a user