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

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

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

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

 

本文内容参考:

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中与图像质量和帧缓冲相关的成员,本回继续解析其它成员。为了便于理解和回顾,再次贴出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 {
    ……
    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;
  • camera_grab_mode_t grab_mode

设置图像数据的抓取模式。上边示例代码中设置为CAMERA_GRAB_WHEN_EMPTY,表示在缓冲区为空时抓取图像。

    .grab_mode = CAMERA_GRAB_WHEN_EMPTY//CAMERA_GRAB_LATEST. Sets when buffers should be filled

camera_grab_mode_t的定义在components\esp32-camera\driver\include\esp_camera.h中,如下:

/**
 * @brief Configuration structure for camera initialization
 */
typedef enum {
    CAMERA_GRAB_WHEN_EMPTY,         /*!< Fills buffers when they are empty. Less resources but first 'fb_count' frames might be old */
    CAMERA_GRAB_LATEST              /*!< Except when 1 frame buffer is used, queue will always contain the last 'fb_count' frames */
} camera_grab_mode_t;

可见,camera_grab_mode_t为枚举类型,包含了两个枚举值:

  • CAMERA_GRAB_WHEN_EMPTY:当缓冲区为空时填充缓冲区。(占用)资源更少,但第一个“fb_count”帧可能是旧的。
  • CAMERA_GRAB_LATEST:除非使用1帧缓冲区,否则队列将始终包含最后的“fb_count”帧。

 

  • camera_conv_mode_t conv_mode

RGB<->YUV转换模式。上边示例代码中并为赋值。注意,此成员是有条件的,必须在CONFIG_CAMERA_CONVERTER_ENABLED宏为非零值的时候才会存在。

camera_conv_mode_t的定义在components\esp32-camera\driver\include\esp_camera.h中,如下:

#if CONFIG_CAMERA_CONVERTER_ENABLED
/**
 * @brief Camera RGB\YUV conversion mode
 */
typedef enum {
    CONV_DISABLE,
    RGB565_TO_YUV422,

    YUV422_TO_RGB565,
    YUV422_TO_YUV420
} camera_conv_mode_t;
#endif

CONFIG_CAMERA_CONVERTER_ENABLED是在menuconfig中定义的,默认并不选择。

  • int sccb_i2c_port

如果pin_sccb_sda为-1,则按编号使用已配置的I2C总线。

8521567084d84c52a16f0c8b964cfbb2.png

至此,camera_config_t结构及其实例camera_config的最后一段代码就解析完了,整个结构体也就都讲解完了。下一回开始正式解析函数代码。

 

标签:10,PIN,pin,S3,esp32,int,camera,mode,CAM
From: https://blog.csdn.net/phmatthaus/article/details/143635415

相关文章

  • 华为OD机试2024年E卷-MVP争夺战[100分]( Java | Python3 | C++ | C语言 | JsNode | Go
    题目描述在星球争霸篮球赛对抗赛中,最大的宇宙战队希望每个人都能拿到MVP,MVP的条件是单场最高分得分获得者。可以并列所以宇宙战队决定在比赛中尽可能让更多队员上场,并且让所有得分的选手得分都相同,然而比赛过程中的每1分钟的得分都只能由某一个人包揽。输入描述输入第一行......
  • 华为OD机试2024年E卷-AI识别面板[100分]( Java | Python3 | C++ | C语言 | JsNode | Go
    题目描述AI识别到面板上有N(1≤N≤100)个指示灯,灯大小一样,任意两个之间无重叠。由于AI识别误差,每次别到的指示灯位置可能有差异,以4个坐标值描述AI识别的指示灯的大小和位置(左上角x1,y1,右下角x2,y2),请输出先行后列排序的指示灯的编号,排序规则:每次在尚未排序的灯中挑选最高的......
  • 国内 ChatGPT中文版镜像网站整理合集(2024/11/10)
    一、GPT中文镜像网站① www.yixiaai.com 支持GPT4、4o以及o1,支持通用全模型② chat.lify.vip 支持GPT3.5/4,4o以及AI绘画,支持AI文件、AI插件、AI绘画、AIPPT③ AIPlus支持GPT3.5/4,4o以及AI绘画1.什么是镜像站镜像站(MirrorSite)是指通过复制原始网站内容和结构,创......
  • P1002 [NOIP2002 普及组] 过河卒
    P1002[NOIP2002普及组]过河卒题目棋盘上AAA点有一个过河卒,需要走到目标BB......
  • CSC1003 OJ system running Java SDK.
    CSC1003Assignment2ImportantNotes:Theassignmentisanindividualproject,tobefinishedonone’sowneffort.Theworkmustbesubmittedbefore6pmNov.8,2024(Friday),BeijingTime.Thisisafirmdeadline.Nolatesubmissionsareaccepted.Plag......
  • 笔趣阁纯净版V2024.10.13
    今天给大家推荐一款非常棒的免费小说阅读软件--笔趣阁纯净版版。不管你是想重温经典文学作品,还是想追读时下最火的小说,这款应用都能满足你的需求。对于小说和漫画爱好者来说,它是一个极佳的阅读工具,带你畅游在书籍的海洋中,享受阅读的乐趣。软件特色:1、界面设计非常简洁,没有......
  • 大二上计组往年卷刷题之简单题部分 202411109
    2020年计组期末卷(非陈家骏班)1.请简述C++程序设计语言的设计理念、演化历程(包括主要的贡献者),并讨论Simula67在其中的作用。C++程序设计语言的设计理念C++的设计理念主要基于以下几个核心原则:高效地使用硬件:C++旨在保持与C语言的兼容性,使得C++代码与C代码运行时具有相似或更......
  • 力扣(LeetCode)106. 从中序与后序遍历序列构造二叉树
    一、目标  给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。二、代码分析总体代码:/***Definitionforabinarytreenode.*publicclassTreeNode{*int......
  • 104.力扣(leetcode)二叉树的最大深度(JAVA)
    一、目标给定一个二叉树 root ,返回其最大深度。二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。二、代码分析总代码:/***Definitionforabinarytreenode.*publicclassTreeNode{*intval;*TreeNodeleft;*TreeN......
  • CSS3中动画的使用animation
    1.基本使用2.其他属性3.复合属性......