首页 > 其他分享 >ESP32-S3模组上跑通esp32-camera(9)

ESP32-S3模组上跑通esp32-camera(9)

时间:2024-11-10 08:48:49浏览次数:3  
标签:pin PIN S3 esp32 int fb camera CAM ESP32

接前一篇文章:ESP32-S3模组上跑通esp32-camera(8)

 

本文内容参考:

esp32-camera入门(基于ESP-IDF)_esp32 camera-CSDN博客

OV5640手册解读-CSDN博客

ESP32_CAM CameraWebServer例程源码解析笔记(一)_void startcameraserver();-CSDN博客

特此致谢!

 

一、OV5640初始化

1. 配置接线和驱动

#include "esp_camera.h"
 
//WROVER-KIT PIN Map
#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
 
static camera_config_t camera_config = {
    .pin_pwdn  = CAM_PIN_PWDN,
    .pin_reset = CAM_PIN_RESET,
    .pin_xclk = CAM_PIN_XCLK,
    .pin_sccb_sda = CAM_PIN_SIOD,
    .pin_sccb_scl = CAM_PIN_SIOC,
 
    .pin_d7 = CAM_PIN_D7,
    .pin_d6 = CAM_PIN_D6,
    .pin_d5 = CAM_PIN_D5,
    .pin_d4 = CAM_PIN_D4,
    .pin_d3 = CAM_PIN_D3,
    .pin_d2 = CAM_PIN_D2,
    .pin_d1 = CAM_PIN_D1,
    .pin_d0 = CAM_PIN_D0,
    .pin_vsync = CAM_PIN_VSYNC,
    .pin_href = CAM_PIN_HREF,
    .pin_pclk = CAM_PIN_PCLK,
 
    .xclk_freq_hz = 20000000,//EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode
    .ledc_timer = LEDC_TIMER_0,
    .ledc_channel = LEDC_CHANNEL_0,
 
    .pixel_format = PIXFORMAT_JPEG,//YUV422,GRAYSCALE,RGB565,JPEG
    .frame_size = FRAMESIZE_UXGA,//QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.
 
    .jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality
    .fb_count = 1, //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
    .grab_mode = CAMERA_GRAB_WHEN_EMPTY//CAMERA_GRAB_LATEST. Sets when buffers should be filled
};
 
esp_err_t camera_init(){
    //power up the camera if PWDN pin is defined
    if(CAM_PIN_PWDN != -1){
        pinMode(CAM_PIN_PWDN, OUTPUT);
        digitalWrite(CAM_PIN_PWDN, LOW);
    }
 
    //initialize the camera
    esp_err_t err = esp_camera_init(&camera_config);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Camera Init Failed");
        return err;
    }
 
    return ESP_OK;
}
 
esp_err_t camera_capture(){
    //acquire a frame
    camera_fb_t * fb = esp_camera_fb_get();
    if (!fb) {
        ESP_LOGE(TAG, "Camera Capture Failed");
        return ESP_FAIL;
    }
    //replace this with your own function
    process_image(fb->width, fb->height, fb->format, fb->buf, fb->len);
  
    //return the frame buffer back to the driver for reuse
    esp_camera_fb_return(fb);
    return ESP_OK;
}

上一回讲解了camera_config_t中LEDC的相关成员,本回继续解析其它成员。为了便于理解和回顾,再次贴出camera_config_t的定义,在components\esp32-camera\driver\include\esp_camera.h中,如下:

/**
 * @brief Configuration structure for camera initialization
 */
typedef struct {
    int pin_pwdn;                   /*!< GPIO pin for camera power down line */
    int pin_reset;                  /*!< GPIO pin for camera reset line */
    int pin_xclk;                   /*!< GPIO pin for camera XCLK line */
    union {
        int pin_sccb_sda;           /*!< GPIO pin for camera SDA line */
        int pin_sscb_sda __attribute__((deprecated("please use pin_sccb_sda instead")));           /*!< GPIO pin for camera SDA line (legacy name) */
    };
    union {
        int pin_sccb_scl;           /*!< GPIO pin for camera SCL line */
        int pin_sscb_scl __attribute__((deprecated("please use pin_sccb_scl instead")));           /*!< GPIO pin for camera SCL line (legacy name) */
    };
    int pin_d7;                     /*!< GPIO pin for camera D7 line */
    int pin_d6;                     /*!< GPIO pin for camera D6 line */
    int pin_d5;                     /*!< GPIO pin for camera D5 line */
    int pin_d4;                     /*!< GPIO pin for camera D4 line */
    int pin_d3;                     /*!< GPIO pin for camera D3 line */
    int pin_d2;                     /*!< GPIO pin for camera D2 line */
    int pin_d1;                     /*!< GPIO pin for camera D1 line */
    int pin_d0;                     /*!< GPIO pin for camera D0 line */
    int pin_vsync;                  /*!< GPIO pin for camera VSYNC line */
    int pin_href;                   /*!< GPIO pin for camera HREF line */
    int pin_pclk;                   /*!< GPIO pin for camera PCLK line */
 
    int xclk_freq_hz;               /*!< Frequency of XCLK signal, in Hz. EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode */
 
    ledc_timer_t ledc_timer;        /*!< LEDC timer to be used for generating XCLK  */
    ledc_channel_t ledc_channel;    /*!< LEDC channel to be used for generating XCLK  */
 
    pixformat_t pixel_format;       /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG  */
    framesize_t frame_size;         /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA  */
 
    int jpeg_quality;               /*!< Quality of JPEG output. 0-63 lower means higher quality  */
    size_t fb_count;                /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed)  */
    camera_fb_location_t fb_location; /*!< The location where the frame buffer will be allocated */
    camera_grab_mode_t grab_mode;   /*!< When buffers should be filled */
#if CONFIG_CAMERA_CONVERTER_ENABLED
    camera_conv_mode_t conv_mode;   /*!< RGB<->YUV Conversion mode */
#endif
 
    int sccb_i2c_port;              /*!< If pin_sccb_sda is -1, use the already configured I2C bus by number */
} camera_config_t;

接下来关注以下成员:

typedef struct {
    ……
    int jpeg_quality;               /*!< Quality of JPEG output. 0-63 lower means higher quality  */
    size_t fb_count;                /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed)  */
    camera_fb_location_t fb_location; /*!< The location where the frame buffer will be allocated */
    ……
} camera_config_t;
  • int jpeg_quality

JPEG输出质量。如果图像格式是JPEG,这里设置JPEG的质量。上边示例代码中设置的值为12。

    .jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality

对于OV(Omni Vision)系列的相机传感器,数值越低意味着质量越高。

  • size_t fb_count

要分配的摄像头图像帧缓冲的数量。如果多于一个,则将获取每一帧(双倍速度)。上边示例代码中设置的值为1,即1个帧缓冲(区)。

    .fb_count = 1, //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
  • camera_fb_location_t fb_location

帧缓冲将被分配的位置。上边示例代码中并未做设置。一般设置为CAMERA_FB_IN_PSRAM,表示使用PSRAM存储图像数据(存放在外部PSRAM中,还可选择内部DRAM)。

 

这样,camera_config_t结构及其实例camera_config的第7段代码就解析完了,下一回继续往下解析。

 

标签:pin,PIN,S3,esp32,int,fb,camera,CAM,ESP32
From: https://blog.csdn.net/phmatthaus/article/details/143592313

相关文章

  • ESP32-S3模组上跑通esp32-camera(10)
    接前一篇文章:ESP32-S3模组上跑通esp32-camera(9) 本文内容参考:esp32-camera入门(基于ESP-IDF)_esp32camera-CSDN博客OV5640手册解读-CSDN博客ESP32_CAMCameraWebServer例程源码解析笔记(一)_voidstartcameraserver();-CSDN博客特此致谢! 一、OV5640初始化1.配置接线和......
  • CSS3中动画的使用animation
    1.基本使用2.其他属性3.复合属性......
  • esp32实现简单的kv数据库
    我来帮你优化代码,使用SPIFFS(SPIFlashFileSystem)来实现数据持久化存储。#include<ESP8266WebServer.h>#include<ESP8266WiFi.h>#include<FS.h>#include<ArduinoJson.h>//WiFi设置constchar*ssid="你的WiFi名称";constchar*password=&quo......
  • EB配置S32K144 MCAL的Icu
    作者:幸运的双鱼免责声明: 本文为个人学习笔记及总结,仅代表个人观点,尽可能保证内容准确性。复制/转发请注明来源/作者。Icu介绍   Icu模块是输入捕捉功能,可以获取频率、占空比、高低电平等状态,在电机控制中,一般使用在硬件故障的触发脚,用于硬件的过压、过流等故障通知......
  • ESP32学习笔记2(GPIO的数字输入输出功能)
    1.普通5mm直径LED参数测定实验以上为普通5mm直径LED,手册建议持续工作电流为20mA以内。以下,采用学生电源(带控压限流功能)通过限流电阻170欧给各色LED供电,通过缓慢加压测流和观察LED亮度的方法,确定电流、压降与亮度关系,实测该批次LED颜色与压降大致如下:颜色1mA状态与压降......
  • 使用 vscode 简单配置 ESP32 连接 Wi-Fi 每日定时发送 HTTP 和 HTTPS 请求
    最新博客文章链接文字更新时间:2024/11/07由于学校校园网,如果长时间不重新登陆的话,网速会下降,所以想弄个能定时发送HTTP请求的东西。由于不想给路由器刷系统,也麻烦。就开始考虑使用局域网内的服务器,不过由于服务器没有Wi-Fi模块,也不想搞USB无线wifi网卡,就想着干脆用单......
  • CSS3实现放大镜效果
    市面上基本上所有的购物平台、商城上的商品详情页,对于商品的图片都是有放大功能。那么这个功能主要是怎么实现的呢?CSS3实现放大镜效果主要依赖于CSS的一些高级特性,如transform、transition和::before伪元素等其实代码并没有多少,这里用了6款静态资源图片作为示例,但是每一款都需要......
  • CSS3实现放大镜效果
    市面上基本上所有的购物平台、商城上的商品详情页,对于商品的图片都是有放大功能。那么这个功能主要是怎么实现的呢?CSS3实现放大镜效果主要依赖于CSS的一些高级特性,如transform、transition和::before伪元素等其实代码并没有多少,这里用了6款静态资源图片作为示例,但是每一款都需......
  • nodejs通过s3-zip对AWS-S3服务上的文件下载操作
    这里对接的是百度智能云对象存储服务,用的是aws-sdk进行服务对接的,遵照的标准都是AWSS3服务那一套标准。1、awss3服务对接的基本配置及操作流程参考博文:https://blog.csdn.net/LegendaryChen/article/details/1297753042、单个存储文件对象的下载://导入依赖constAWS=req......
  • 纯HTML5+CSS3实现一棵自己跳舞的树
    代码没有多少,也没有用到任何图片,就实现了一棵可以自己跳舞的树。文件组成就简简单单的一个html和一个csshtml部分并不是很复杂,就是一些空的div,然后加上html模板也就那么十来行代码最关键的还是css部分,也不是很多,总共一百来行但就是上面这么简简单单的两个文件可以绘画出一......