拿到这个板子之后,第一件事就是好奇这个板子还有几个引脚可以让我来使用?



看看代码中定义了几个引脚:

#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

这里只定义了15个引脚。

视频质量:

const int resolution[][2] = {{ 160, 120 }, /* QQVGA */{ 128, 160 }, /* QQVGA2*/{ 176, 144 }, /* QCIF  */{ 240, 176 }, /* HQVGA */{ 320, 240 }, /* QVGA  */{ 400, 296 }, /* CIF   */{ 640, 480 }, /* VGA   */{ 800, 600 }, /* SVGA  */{ 1024, 768 }, /* XGA  */{ 1280, 1024 }, /* SXGA  */{ 1600, 1200 }, /* UXGA  */{ 2048, 1536 }, /* QXGA  */
};

摄像头OV2640的资料:https://wiki.ai-thinker.com/media/esp32/docs/ov2640_ds_1.8.pdf

使用最小的QQVGA(160*120)–(2450Byte/25fps)大概100Byte每帧。

MJPG: 2449B 41ms (24.4fps), AVG: 39ms (25.6fps), 0+0+0+0=0 0
MJPG: 2456B 38ms (26.3fps), AVG: 39ms (25.6fps), 0+0+0+0=0 0
MJPG: 2451B 39ms (25.6fps), AVG: 39ms (25.6fps), 0+0+0+0=0 0

使用最大的UXGA(1600*1200)-- (84500Byte/4fps)大概21125Byte每帧。

MJPG: 84369B 351ms (2.8fps), AVG: 263ms (3.8fps), 0+0+0+0=0 0
MJPG: 84407B 259ms (3.9fps), AVG: 272ms (3.7fps), 0+0+0+0=0 0
MJPG: 84208B 247ms (4.0fps), AVG: 262ms (3.8fps), 0+0+0+0=0 0

效果图:
实现代码:

#include <WiFi.h>
#include "esp_http_server.h"
#include "esp_camera.h"
#include "esp_timer.h"
#include "dl_lib.h"const char* ssid = "liefyuan";
const char* password = "1234567890";#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22#define PART_BOUNDARY "123456789000000000000987654321"
static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char* _STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n";typedef struct {size_t size; //number of values used for filteringsize_t index; //current value indexsize_t count; //value countint sum;int * values; //array to be filled with values
} ra_filter_t;httpd_handle_t stream_httpd = NULL;
httpd_handle_t camera_httpd = NULL;
static ra_filter_t ra_filter;static int ra_filter_run(ra_filter_t * filter, int value){if(!filter->values){return value;}filter->sum -= filter->values[filter->index];filter->values[filter->index] = value;filter->sum += filter->values[filter->index];filter->index++;filter->index = filter->index % filter->size;if (filter->count < filter->size) {filter->count++;}return filter->sum / filter->count;
}static esp_err_t stream_handler(httpd_req_t *req){camera_fb_t * fb = NULL;esp_err_t res = ESP_OK;size_t _jpg_buf_len = 0;uint8_t * _jpg_buf = NULL;char * part_buf[64];dl_matrix3du_t *image_matrix = NULL;bool detected = false;int face_id = 0;int64_t fr_start = 0;int64_t fr_ready = 0;int64_t fr_face = 0;int64_t fr_recognize = 0;int64_t fr_encode = 0;static int64_t last_frame = 0;if(!last_frame) {last_frame = esp_timer_get_time();}res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);if(res != ESP_OK){return res;}while(true){detected = false;face_id = 0;sensor_t * s = esp_camera_sensor_get();s->set_vflip(s, 1);fb = esp_camera_fb_get();if (!fb) {Serial.println("Camera capture failed");res = ESP_FAIL;} else {fr_start = esp_timer_get_time();_jpg_buf_len = fb->len;_jpg_buf = fb->buf; }if(res == ESP_OK){size_t hlen = snprintf((char *)part_buf, 64, _STREAM_PART, _jpg_buf_len);res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);}if(res == ESP_OK){res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);}if(res == ESP_OK){res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));}if(fb){esp_camera_fb_return(fb);fb = NULL;_jpg_buf = NULL;} else if(_jpg_buf){free(_jpg_buf);_jpg_buf = NULL;}if(res != ESP_OK){break;}int64_t fr_end = esp_timer_get_time();int64_t ready_time = (fr_ready - fr_start)/1000;int64_t face_time = (fr_face - fr_ready)/1000;int64_t recognize_time = (fr_recognize - fr_face)/1000;int64_t encode_time = (fr_encode - fr_recognize)/1000;int64_t process_time = (fr_encode - fr_start)/1000;int64_t frame_time = fr_end - last_frame;last_frame = fr_end;frame_time /= 1000;uint32_t avg_frame_time = ra_filter_run(&ra_filter, frame_time);Serial.printf("MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps), %u+%u+%u+%u=%u %s%d\n",(uint32_t)(_jpg_buf_len),(uint32_t)frame_time, 1000.0 / (uint32_t)frame_time,avg_frame_time, 1000.0 / avg_frame_time,(uint32_t)ready_time, (uint32_t)face_time, (uint32_t)recognize_time, (uint32_t)encode_time, (uint32_t)process_time,(detected)?"DETECTED ":"", face_id);}last_frame = 0;return res;
}void start_camera_server(void)
{httpd_config_t config = HTTPD_DEFAULT_CONFIG();httpd_uri_t    stream_uri = {.uri         = "/stream",.method      = HTTP_GET,.handler     = stream_handler,.user_ctx    = NULL};config.server_port += 1;config.ctrl_port += 1;Serial.printf("Starting stream server on port: '%d'\n/stream", config.server_port);if (httpd_start(&stream_httpd, &config) == ESP_OK) {httpd_register_uri_handler(stream_httpd, &stream_uri);}
}void setup()
{Serial.begin(115200);Serial.setDebugOutput(true);Serial.println();camera_config_t config;config.ledc_channel = LEDC_CHANNEL_0;config.ledc_timer = LEDC_TIMER_0;config.pin_d0 = Y2_GPIO_NUM;config.pin_d1 = Y3_GPIO_NUM;config.pin_d2 = Y4_GPIO_NUM;config.pin_d3 = Y5_GPIO_NUM;config.pin_d4 = Y6_GPIO_NUM;config.pin_d5 = Y7_GPIO_NUM;config.pin_d6 = Y8_GPIO_NUM;config.pin_d7 = Y9_GPIO_NUM;config.pin_xclk = XCLK_GPIO_NUM;config.pin_pclk = PCLK_GPIO_NUM;config.pin_vsync = VSYNC_GPIO_NUM;config.pin_href = HREF_GPIO_NUM;config.pin_sscb_sda = SIOD_GPIO_NUM;config.pin_sscb_scl = SIOC_GPIO_NUM;config.pin_pwdn = PWDN_GPIO_NUM;config.pin_reset = RESET_GPIO_NUM;config.xclk_freq_hz = 20000000;config.pixel_format = PIXFORMAT_JPEG;if(psramFound()){config.frame_size = FRAMESIZE_UXGA;config.jpeg_quality = 10;config.fb_count = 2;} else {config.frame_size = FRAMESIZE_SVGA;config.jpeg_quality = 12;config.fb_count = 1;}// camera initesp_err_t err = esp_camera_init(&config);if (err != ESP_OK) {Serial.printf("Camera init failed with error 0x%x", err);return;}//drop down frame size for higher initial frame ratesensor_t * s = esp_camera_sensor_get();s->set_framesize(s, FRAMESIZE_QVGA);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.println("");Serial.println("WiFi connected");start_camera_server();Serial.print("Camera Ready! Use 'http://");Serial.print(WiFi.localIP());Serial.println("' to connect");
}void loop()
{delay(10);
}

ESP32-CAM 使用 (二)相关推荐

  1. esp32 cam工作电流_我如何在家工作:Cam的生产力之痛

    esp32 cam工作电流 Telecommuting is becoming more and more common these days, with many tech writers (mys ...

  2. esp32 cam 从安装、烧录到成为webcam详细教程

    前言:本教程仅适用于ESP32-CAM开发板且带下载主板的这种情况. 一.安装arduino 1.arduino下载地址: ''' https://www.arduino.cc/en/Main/Sof ...

  3. esp32 cam接入homekit苹果家庭app

    mac平台esp32 cam接入homekit苹果家庭app 一.准备: 1.esp32-cam模块,串口工具 2.brew 二.开始吧 1.安装一些工具 sudo easy_install pip ...

  4. 自行编译micropython固件刷入ESP32 cam,并测试拍照及图传

    一.环境准备 1.Ubuntu20.04LTS 2.ESP-IDF 3.micropython 操作步骤 1.安装基于Windows的linux子系统 适用于 Linux 的 Windows 子系统安 ...

  5. ESP32 CAM与服务器(python)UDP视频传输

    ESP32 CAM Arduino代码 #include "esp_camera.h" #include <WiFi.h> #include "AsyncUD ...

  6. esp32 cam 配网 实现视频传输

    esp32 cam 1.实现配网 1.1.WiFiManager使用 2.视频传输 2.1 .修改代码 2.2 .配网操作 2.3 .查看视频   实现功能首先默认连接代码里面写入的WiFi信息,如果 ...

  7. esp32 cam 1.44寸TFT彩屏 ST7735S驱动 TFT_eSPI库驱动

    ESP32 CAM引脚与TFT1.44(ST7735S)引脚接线 ESP32 CAM TFT 1.44 5V VCC GND GND GND NC NC 5V BLC D14 SCL D15 SDA ...

  8. ESP32 CAM下载程序踩过的吭

    最近几天想玩一下ESP32 CAM,做个简单的摄像头,今天终于不再报错了,特别记录一下,方便自己也方便他人. 说明一下cam自闪光灯是4号IO口,高电平亮 digitalWrite(4, HIGH); ...

  9. 基于ESP32 CAM的人脸识别考勤系统

    概述:使用 ESP32 CAM 的人脸识别考勤系统 本教程介绍了使用ESP32 CAM 模组的人脸识别考勤系统.我们将为此应用程序使用OpenCV和Visual Studio .OpenCV 是一个开 ...

  10. ESP32 CAM CameraWebServer示例测试

    一.下载资源 CAM资料链接:https://pan.baidu.com/s/1dL-qZKXrnKhcRCXIZtZabA 提取码:q20d 二.安装ESP32插件 在本例中,我们使用Arduino ...

最新文章

  1. jQuery省市区三级联动插件
  2. 用iPhone给林徽因拍照会是啥样?这款“穿越相机”把老照片换成现代风
  3. 爱立信总裁表示欧洲网络始终趋于落后,网站推广之下5G发展需加快步伐
  4. 未来CRM的趋势和预测
  5. Fishe向量Fisher Vecotr(二)
  6. 随心篇第九期:我不愿一无所有
  7. SAP CRM Fiori应用My Opportunity的点阵外观
  8. ios支付宝支付失败不回调_iOS 支付宝网页支付回调问题
  9. 图Graph--最小生成树
  10. [转]WF事件驱动(1)
  11. 哪里有c语言在线编程题,在线求C语言编程题答案。。。
  12. 星际迷航的William Shatner发推文支持Vitalik Buterin
  13. 读书笔记:Dynamic GCN: Context-enriched Topology Learning for Skeleton-based Action Recognition
  14. mPaas之如何查找离线包的在线加载地址
  15. 如何做好硕士论文的排版
  16. 软件工程计算机导论试题及答案,2010级计算机学院计算机导论试题A卷.doc
  17. 基于Android Q 修改默认音量等级
  18. 2.4G遥控感应橱柜灯酒柜氛围灯
  19. 【推荐收藏】机器学习12种回归评价指标(附Python代码)
  20. mybatis 核心思想

热门文章

  1. java ilvmanagerview_Android 腾讯互动直播集成
  2. MySQL 8.0.11免安装版配置步骤
  3. C#利用EXCEL做報表
  4. c# 不规则透明窗体
  5. sequel pro 连接mysql_Sequel Pro 客户端连接 MySQL 失败
  6. 探地雷达(GPR)详解
  7. frp穿透内网 使用stcp进行P2P穿透3389远程桌面端口实战
  8. python怎么控制鼠标_Python使用pyautogui控制鼠标键盘
  9. 双一流学校、双一流学科都分别有哪些?
  10. 基于Android实现的天气预测APP