esp32cam和esp32-s3烧录human_face_detect实现人脸识别

如果使用ubuntu 16.04在后续的步骤中会报错如下,因为ubuntu 16.04不支持glibc2.23以上的版本(可使用strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_命令查询)。所以建议使用18.04以上的ubuntu进行烧录。

OSError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by /home/zhouying/Desktop/ESP32CAM/esp-dl/tools/tvm/python/tvm/libtvm.so)

一、环境搭建


1. 下载esp-dl

git clone https://github.com/espressif/esp-dl.git

2. 安装esp-idf

官方文档:Linux 和 macOS 平台工具链的标准设置

我安装的版本是5.0.4,其他的版本会在某一步出现版本不兼容的问题。

打开https://github.com/espressif/esp-idf/tree/v5.0.4,选择手动下载压缩文件到本地。

在这里插入图片描述

cd esp-idf-v5.0.4/
./install.sh # 也可以指定单个芯片安装 ./install.sh esp32

# 设置环境
export IDF_PATH=/home/zhouying/Downloads/esp-idf-v5.0.4
export IDF_TOOLS_PATH=/home/zhouying/.espressif

在需要运行ESP-IDF的终端窗口运行(不建议直接将export.sh添加到shell的配置文件,这样会导致在每个终端会话中都激活IDF虚拟环境):

~$ source /home/zhouying/Downloads/esp-idf-v5.0.4/export.sh
Detecting the Python interpreter
Checking "python3" ...
Python 3.10.9
"python3" has been detected
Checking Python compatibility
Checking other ESP-IDF version.
Adding ESP-IDF tools to PATH...
Checking if Python packages are up to date...
Constraint file: /home/zhouying/.espressif/espidf.constraints.v5.0.txt
Requirement files:
 - /home/zhouying/Downloads/esp-idf-v5.0.4/tools/requirements/requirements.core.txt
Python being checked: /home/zhouying/.espressif/python_env/idf5.0_py3.10_env/bin/python
Python requirements are satisfied.
Added the following directories to PATH:
  /home/zhouying/Downloads/esp-idf-v5.0.4/components/espcoredump
  /home/zhouying/Downloads/esp-idf-v5.0.4/components/partition_table
  /home/zhouying/Downloads/esp-idf-v5.0.4/components/app_update
  /home/zhouying/.espressif/python_env/idf5.0_py3.10_env/bin
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

二、esp32-cam


在这里插入图片描述

烧录human_face_detect

cd esp-dl/examples/human_face_detect
idf.py set-target esp32
idf.py flash monitor -p /dev/ttyUSB0

如果报错A fatal error occurred: Could not open /dev/ttyUSB0, the port doesn't exist,先修改权限sudo chmod a+rw /dev/ttyUSB0,再重新运行

~$ idf.py flash monitor -p /dev/ttyUSB0
...
I (1214) main_task: Calling app_main()
Inference latency:          411416 us
[0] score: 0.999874, box: [-1, -1, 268, 299]
    left eye: (126,  75), right eye: (189,  73)
    nose: (119, 194)
    mouth left: ( 41, 141), mouth right: (263, 212)

[1] score: 0.999810, box: [5, 206, 233, 506]
    left eye: (118, 268), right eye: (170, 291)
    nose: (115, 352)
    mouth left: ( 55, 303), mouth right: (303, 415)

[2] score: 0.896976, box: [125, 255, 385, 556]
    left eye: (217, 330), right eye: (252, 341)
    nose: (185, 390)
    mouth left: (194, 333), mouth right: (349, 465)

I (1674) main_task: Returned from app_main()

Done

esp32的结果跑出来和官方的不一样,应该是芯片性能原因。

在这里插入图片描述

三、esp32-s3


在这里插入图片描述

烧录human_face_detect

esp32-s3的指导文件:esp32-s3-eye,esp32-s3连接linux显示的串口名称是ttyACM*

cd esp-dl/examples/human_face_detect
idf.py set-target esp32s3
idf.py flash monitor -p /dev/ttyACM0

如果报错A fatal error occurred: Could not open /dev/ttyACM0, the port doesn't exist,先修改权限sudo chmod a+rw /dev/ttyACM0,再重新运行。

报错:

(359) quad_psram: PSRAM ID read error: 0x00ffffff, PSRAM chip not found or not supported, or wrong PSRAM line mode
E (362) cpu_start: Failed to init external RAM!

在这里插入图片描述

原因是PSRAM的模式错误,ESP32-S3内置的PSRAM为八线模式(Octal mode PSRAM)。参考ESP32 s3 PSRAM ID read error: 0x00ffffff 已解决。解决方法如下:
终端运行idf.py menuconfig打开工程配置,按照下图修改PSRAM的模式,然后S键+回车保存,Q键退出。

在这里插入图片描述
再重新运行idf.py flash monitor -p /dev/ttyACM0

~$ idf.py flash monitor -p /dev/ttyACM0
...
I (803) cpu_start: Max chip rev:     v0.99 
I (808) cpu_start: Chip rev:         v0.1
I (812) heap_init: Initializing. RAM available for dynamic allocation:
I (820) heap_init: At 3FC99248 len 000504C8 (321 KiB): DRAM
I (826) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (833) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
I (839) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
I (847) spi_flash: detected chip: generic
I (851) spi_flash: flash io: qio
W (855) spi_flash: Detected size(8192k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (873) app_start: Starting scheduler on CPU0
I (873) app_start: Starting scheduler on CPU1
I (873) main_task: Started on CPU0
I (883) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (893) main_task: Calling app_main()
Inference latency:           55619 us
[0] score: 0.987812, box: [137, 75, 246, 215]
    left eye: (157, 131), right eye: (199, 133)
    nose: (170, 163)
    mouth left: (158, 177), mouth right: (193, 180)

I (963) main_task: Returned from app_main()

Done

按照它的输出查看下识别效果,可以看到效果不错,说明s3的芯片性能还是很不错的。

cd /home/zhouying/Desktop/esp32-cam/esp-dl/examples/tool

python display_image.py -i /home/zhouying/Desktop/esp32-cam/esp-dl/examples/human_face_detect/image.jpg -b "(137, 75, 246, 215)" -k "(157, 131, 199, 133, 170, 163, 158, 177, 193, 180)"

在这里插入图片描述

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的ESP32-CAM人脸识别示例代码,需要使用到Arduino IDE和ESP32-CAM的相关库: ``` #include "esp_camera.h" #include <Arduino.h> #include "camera_index.h" #include "face_detection.h" #define ENABLE_IP5306 #include <axp20x.h> AXP20X_Class axp; #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 const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD"; String message = ""; void setup() { Serial.begin(115200); Serial.setDebugOutput(true); Serial.println(); axp.begin(); axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); axp.setDCDC3(false); axp.setLDO2(true); axp.setLDO3(true); axp.setChargeVoltage(AXP192_4_2V); axp.setChargeCurrent(AXP192_100MA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("WiFi connected!"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); 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; config.frame_size = FRAMESIZE_QVGA; config.jpeg_quality = 12; config.fb_count = 1; esp_err_t err = esp_camera_init(&config); if (err != ESP_OK) { Serial.printf("Camera init failed with error 0x%x", err); return; } Serial.println("Camera initialized"); delay(1000); Serial.println("Starting face detection..."); while (true) { camera_fb_t *fb = esp_camera_fb_get(); if (!fb) { Serial.println("Failed to capture frame"); continue; } face_detection_result_t result = detect_faces(fb->buf, fb->len); Serial.printf("%d faces detected\n", result.num_faces); if (result.num_faces > 0) { message = "Someone is in front of the camera!"; } else { message = "No one in front of the camera."; } esp_camera_fb_return(fb); delay(1000); } } void loop() { Serial.println(message); delay(1000); } ``` 需要注意的是,此代码中的 `detect_faces()` 函数是一个自定义函数,用于执行人脸检测,需要自己实现或使用第三方库。此外,还需要在Arduino IDE中添加ESP32-CAM的相关库,具体方法可以参考ESP32-CAM的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值