Chapter 9 Person_detection 範例程式
本範例使用 Espressif 的 ESP32-CAM 開發板來操作人像辨識功能
9.1 ESP32-CAM 於 esp-idf 開發環境
在 §3.7 esp-idf 安裝 ESP32-CAM 開發環境後, 進一步測試人物辨識程式 person_detection
$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_person_detection_esp_project
出現 github 已經在討論的 ESP32-CAM person_detectin problem, 我試過後, 加入我的可行作法
$ git clone --depth 1 https://github.com/tensorflow/tensorflow.git
$ cd tensorflow/
$ make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_person_detection_esp_project
# error occurs, same as yours, I believe.
# 下載 https://patch-diff.githubusercontent.com/raw/tensorflow/tensorflow/pull/47063.patch
# 或是 git cherry-pick 6d69beaf73fa2488f830a7fb7ed4ef931b44ce1d
$ ls 47063.patch # to make sure patch is downloaded
$ git apply ./47063.patch
$ make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_person_detection_esp_project
# it generate another error below and stop.
make: *** No rule to make target 'tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32_default/prj/person_detection/esp-idf/main/person_model_int8/person_detect_model_data.cc', needed by 'generate_person_detection_esp_project'. Stop.
$ make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_person_detection_esp_int8_project
# this command generate another error of below, but it seems fix the previous error.
make: *** No rule to make target 'generate_person_detection_esp_int8_project'. Stop.
$ make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_person_detection_esp_project
# so we re-do the generate_person_detection_esp_project again, it works and no error.
接下來, 執行 esp-idf 指令
$ cd tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32/prj/person_detection/esp-idf
$ idf.py build
$ idf.py -p PORT flash monitor
這時候, ESP32-CAM 的執行結果傳回電腦的以下的錯誤訊息
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
[E][camera.c:1049] camera_probe(): Detected camera not supported.
[E][camera.c:1249] esp_camera_init(): Camera probe failed with error 0x20004
Camera init failed
InitCamera failed
Image capture failed
找到 esp-32 Camera probe failed with error 0x20004 文章提到 2 個可能
- ESP32-CAM 從 3.3V 改成 5V
- 將程式原始設定的預設的開發板 WROVER-KIT With OV2640 Module 改成 CAMERA_MODEL_AI_THINKER, 需要修改 2 個檔案
- examples/person_detection/esp/app_camera_esp.h
- 似乎是需要在 menuconfig 中做設定, 將 CONFIG_CAMERA_MODEL_AI_THINKER 設成 TRUE
- 似乎是需要在 menuconfig 中做設定, 將 CONFIG_CAMERA_MODEL_AI_THINKER 設成 TRUE
- examples/person_detection/esp/main/Kconfig.projbuild 第 17 行
- examples/person_detection/esp/app_camera_esp.h
#if CONFIG_CAMERA_MODEL_WROVER_KIT
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
..... skipped ......
#elif CONFIG_CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
# 修改 examples/person_detection/esp/main/Kconfig.projbuild 第 17 行
default CAMERA_MODEL_WROVER_KIT # line 17
# 改成
default ESP32-CAM by AI-Thinker
- Arduino: 下面的範例, 需要修改的設定如下:
// Select camera model
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
#define CAMERA_MODEL_AI_THINKER
9.2 ESP32-CAM 於 Arduino 開發環境
此範例 運用 TinyML 於 ESP32-CAM 人體偵測 初體驗 不是使用 TFLM 的標準範例, 而是針對 ESP32-CAM 開發的特定範例, 這範例的好處是可以在 Arduino 的 serial monitor 上畫出 camera 偵測到的簡圖. (TFLM 原始範例僅僅輸出偵測出人像的可能性)