问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

espwho 人脸识别 esp32人脸识别源码

创作时间:
作者:
@小白创作中心

espwho 人脸识别 esp32人脸识别源码

引用
51CTO
1.
https://blog.51cto.com/u_12218/10446438

本文详细介绍了ESP32-Face人脸识别中的MTMN模型及其相关API函数。文章深入解析了MTMN模型的结构、工作流程以及配置参数,并提供了具体的代码示例。对于对嵌入式设备人脸识别技术感兴趣的开发者来说,本文具有较高的参考价值。

ESP32-Face 人脸检测MTMN模型以及 face_detect 函数详解

  1. MTMN 模型
  2. 模型网络
  3. API 函数接口介绍
  4. 模式选择
  5. 参数配置

1. MTMN 模型

MTMN 是一个人脸检测的轻量级模型,专门应用于嵌入式设备。它是由MTCCN和MobileNets结合而成。

2. 模型网络

MTMN由三个主要部分组成:

  • 提议网络,Proposal Network(P-Net):提议候选边界框,并将其发送到R-Net;

  • 细化网络,Refine Network(R-Net):从P-Net中筛选边界框;

  • 输出网络,Output Network (O-Net):输出最终结果,即精确的边界框、置信系数和5点标记。(accurate bounding box、confidence coefficient and 5-point-landmark)

下图显示了MTNM的工作流程

3. API 函数接口介绍


box_array_t *face_detect(dl_matrix3du_t *image_matrix, mtmn_config_t *config);  

face_detect()

函数处理整个人脸检测的任务。

函数参数—输入:

  • image_matrix: 一帧

dl_matrix3du_t

类型的图像

  • config: MTMN的配置信息。配置信息如下文介绍。

函数输出:

  • 一个

box_array_t

类型的值,包括 face boxes,以及每个框的 score and landmark,其中 len 表示每帧图像中人脸的数量


typedef struct tag_box_list  

{  

    fptp_t *score;  

    box_t *box;  

    landmark_t *landmark;  

    int len;  

} box_array_t;  

MTMN 的配置信息:

mtmn_config_t

结构体详解,结构体中相关参数可以供用户自己修改


typedef struct  

{  

    float min_face;                 /// 检测到人脸的最小尺寸  

    float pyramid;                  /// 输入图像的梯度缩放比例  

    int pyramid_times;              /// 金字塔调整大小的时间  

    threshold_config_t p_threshold; ///  P-Net 的阈值  

    threshold_config_t r_threshold; ///  N-Net 的阈值  

    threshold_config_t o_threshold; ///  O-Net 的阈值  

    mtmn_resize_type type;          /// 图像调整大小类型. 当 'type'==FAST时,'pyramid'将失效  

} mtmn_config_t;  

typedef struct  

{  

    float score;          /// 置信系数的阈值。置信系数低于阈值的候选边界框将被过滤掉。  

    float nms;            /// NMS的阈值。在非最大抑制期间,重叠比率高于阈值的候选边界框将被过滤掉。  

    int candidate_number; /// 允许的候选边界框的最大数量。仅保留所有候选边界框的第一个“candidate_number”。  

} threshold_config_t;  
  • min_face:

  • 范围:12~n,n为输入图像的的最短边的长度

  • 对于固定大小的原始输入图像,

min_face

的值越小,则表示以下三点,反之亦然

  • 生成的不同size图像数量越多

  • 可检测的人脸的size越小

  • 处理时间越长

  • pyramid

  • 指定控制生成的金字塔(pyramid)的比例

  • 范围: (0,1)

  • 对于固定大小的原始输入图像,

minpyramid_face

的值越大,则表示以下三点,反之亦然

  • 生成的不同size图像数量越多

  • 检测比越高

  • 处理时间越长

  • pyramid_times

  • 指定控制生成的金字塔(pyramid)的数量

  • Range: [1,+inf)

  • pyramidmin_face一起, 可以在[min_face, min_face/pyramid^pyramid_times] 以及min_face/pyramid^pyramid_times < 输入原始图像的最短边的长度 这两个范围下确定主要可检测人脸的size

  • type

  • options:

FAST

or

NORMAL

FAST

: 默认pyramid=

0.707106781

. pyramid 值相同情况下吗,fast 类型速度更快

NORMAL

:自定义pyramid的值

  • score threshold

  • Range: (0,1)

  • 对于固定大小的原始输入图像,

score

的值越大,则表示以下2点,反之亦然

  • 过滤出的候选边界框的数量越大

  • 检测率越低

  • nms threshold

  • Range: (0,1)

  • 对于固定大小的原始输入图像,

score

的值越大,则表示以下2点,反之亦然

  • –检测到重叠面的可能性越高;

  • -检测到的同一人脸的候选边界框的数量越大

  • candidate number

  • 指定每个网络的输出候选框的数量。

  • 范围:P-Net: [1, 200] R-Net: [1, 100] O-Net: [1, 10]

  • 对于固定大小的原始输入图像

candidate_number

越大,处理时间越长

  • O-Net的

candidate_number

值越大,检测到的人脸数量越多,

用户可自定义以下参数:


mtmn_config.type = FAST;  

mtmn_config.min_face = 80;  

mtmn_config.pyramid = 0.707;  

mtmn_config.pyramid_times = 4;  

mtmn_config.p_threshold.score = 0.6;  

mtmn_config.p_threshold.nms = 0.7;  

mtmn_config.p_threshold.candidate_number = 20;  

mtmn_config.r_threshold.score = 0.7;  

mtmn_config.r_threshold.nms = 0.7;  

mtmn_config.r_threshold.candidate_number = 10;  

mtmn_config.o_threshold.score = 0.7;  

mtmn_config.o_threshold.nms = 0.7;  

mtmn_config.o_threshold.candidate_number = 1;  

4. 模式选择

MTMN 目前为止有以下版本:

  • MTMN lite in quantization (default)

  • MTMN lite in float

  • MTMN heavy in quantization

5. 参数配置

我们使用相同的配置和我们自己的测试集评估所有型号。结果如下所示。


mtmn_config.type = FAST;  

mtmn_config.pyramid = 0.707;  

mtmn_config.min_face = 80;  

mtmn_config.pyramid_times = 4;  

mtmn_config.p_threshold.score = 0.6;  

mtmn_config.p_threshold.nms = 0.7;  

mtmn_config.p_threshold.candidate_number = 100;  

mtmn_config.r_threshold.score = 0.7;  

mtmn_config.r_threshold.nms = 0.7;  

mtmn_config.r_threshold.candidate_number = 100;  

mtmn_config.o_threshold.score = 0.7;  

mtmn_config.o_threshold.nms = 0.7;  

mtmn_config.o_threshold.candidate_number = 1;  

Average Time Consumption (ms)

MTMN lite in quantization 143.19

MTMN lite in float 178.45

MTMN heavy in quantization 242.84

© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号