在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

【EASY EAI Nano開源套件試用體驗】5AI功能測試之多人臉識別

開發板試用精選 ? 來源:開發板試用 ? 作者:電子發燒友論壇 ? 2022-10-11 16:33 ? 次閱讀

本文來源電子發燒友社區,作者:碼農愛學習, 帖子地址:https://bbs.elecfans.com/jishu_2308719_1_1.html



上篇文章,測試了EASY EAI Nano的人臉檢測功能,本篇進行人臉識別功能。

人臉檢測,只是將圖像中的人臉的位置檢測出來,人臉識別,又增加了一部,在檢測到人臉后,還要識別出這張臉是誰的臉。

本篇參考官方文檔:https://www.easy-eai.com/document_details/3/110
1.png

1 API介紹

組件 頭文件以及庫路徑 描述
系統操作組件 easyeai-api/common_api/system_opt 提供線程操作函數
攝像頭組件 easyeai-api/peripheral_api/camera 提供攝像頭操作函數
顯示屏組件 easyeai-api/peripheral_api/display 提供顯示屏操作函數
平面幾何組件 easyeai-api/algorithm_api/geometry 提供簡單幾何運算函數
人臉檢測組件 easyeai-api/algorithm_api/face_detect 提供人臉檢測操作函數
人臉校正組件 easyeai-api/algorithm_api/face_alignment 提供人臉校正操作函數
人臉識別組件 easyeai-api/algorithm_api/face_recognition 提供人臉識別操作函數

主要來看下人臉識別組件。

face_recognition.h的主要內容

//人臉識別初始化函數
int face_recognition_init(rknn_context *ctx, const char * path);
?
//人臉識別執行函數
int face_recognition_run(rknn_context ctx, cv::Mat *face_image, float (*feature)[512]);
?
//人臉識別特征比對函數
float face_recognition_comparison(float *feature_1, float *feature_2, int output_len);
?
//人臉識別釋放函數
int face_recognition_release(rknn_context ctx);

一些參數:

  • ctx:輸入參數,rknn_context句柄
  • path:輸入參數,算法模型路徑
  • face_image:輸入參數,圖像數據輸入(cv::Mat是Opencv的類型)
  • feature:輸出參數,算法輸出的人臉特征碼

face_alignment.h的主要內容

cv::Mat face_alignment(cv::Mat img, cv::Point2f* points);

geometry.h的主要內容

typedef struct{
    float x;
    float y;
}fPoint_t;
?
typedef struct{
    float left;   //x1
    float top;    //y1
    float right;  //x2
    float bottom; //y2
}fRect_t;
?
typedef struct{
    int32_t x;
    int32_t y;
}s32Point_t;
?
typedef struct{
    int32_t left;   //x1
    int32_t top;    //y1
    int32_t right;  //x2
    int32_t bottom; //y2
}s32Rect_t;
?
//判斷點是否在矩形內
extern bool point_in_rect(s32Point_t point, s32Rect_t rect);
?
//計算矩形面積
extern int32_t calc_rect_square(s32Rect_t rect);
?
//找出面積較小矩形
extern s32Rect_t min_rect(s32Rect_t rect1, s32Rect_t rect2);
?
//找出面積較大矩形
extern s32Rect_t max_rect(s32Rect_t rect1, s32Rect_t rect2);
?
//判斷矩形是否相交或相切
extern bool rect_is_intersect(s32Rect_t rect1, s32Rect_t rect2);
?
//計算兩矩形相交部分面積(若相切,面積也為0)
extern int32_t calc_rect_intersect_square(s32Rect_t rect1, s32Rect_t rect2);
?
//計算[兩矩形相交部分面積]與[小矩形面積]之比
extern double calc_intersect_of_min_rect(s32Rect_t rect1, s32Rect_t rect2);
?
//計算兩矩形的交并比
extern double calc_intersect_of_union(s32Rect_t rect1, s32Rect_t rect2);

2 代碼分析與修改

主要的修改是將紅外攝像頭采集和活體檢測去掉,改用外接RGB攝像頭,另外,識別結果的顯示,將更多的信息(識別的id,人物名稱,耗時等)展示在屏幕上。

2.1 圖像采集與顯示線程(主線程)

重新定義識別結果:

typedef struct{
    bool bHasFace;     //是否檢測到人臉
    bool bMatch;       //是否與注冊的人臉匹配
    char idStr[128];   //匹配的人臉的id
    char nameStr[128]; //匹配的人臉的名稱
    float similarity;  //匹配的相似度
    uint64_t useTime;  //匹配用時
    uint32_t x1;       //識別到的人臉框的4個點
uint32_t y1;
uint32_t x2;
uint32_t y2;
}Result_t;

官方例程用到了紅外攝像頭,用于活體檢測,此次測試,為了使用電腦屏幕上的人物圖片進行人臉檢測,去掉了活體檢測功能,并換做只使用USB攝像頭采集RGB圖像進行人臉識別。

主函數邏輯如下,和上篇進行人臉檢測的代碼邏輯類似。

#define COLOR_RED Scalar(255, 0, 0)
#define COLOR_GREEN Scalar(0, 255, 0)
?
int main(int argc, char **argv)
{
int ret = 0;
    int rgbRet = 0;
    disp_screen_t screen = {0};

char *pRGBbuf = NULL;
int skip = 0;

pthread_t mTid;
Result_t *pResult = NULL;

Mat image;
// 1.打開USB攝像頭
ret = usbcamera_init(USB2_0, USB_DIRECT, CAMERA_WIDTH, CAMERA_HEIGHT, 180);
if (ret) {
printf("error: %s, %dn", __func__, __LINE__);
goto exit_donothing;
}

pRGBbuf = NULL;
pRGBbuf = (char *)malloc(IMAGE_SIZE);
if (!pRGBbuf) {
printf("error: %s, %dn", __func__, __LINE__);
ret = -1;
goto exit_freeusb;
}

// 跳過前10幀
skip = 10;
while(skip--) {
ret = usbcamera_getframe(USB2_0, USB_DIRECT, pRGBbuf);
if (ret) {
printf("error: %s, %dn", __func__, __LINE__);
goto exit_freeusb_freebuf;
}
}
?
// 2.創建識別線程,以及圖像互斥鎖
pthread_mutex_init(&img_lock, NULL);
pResult = (Result_t *)malloc(sizeof(Result_t));
if(NULL == pResult){
goto exit_free_all;
}
memset(pResult, 0, sizeof(Result_t));
if(0 != CreateNormalThread(detect_thread_entry, pResult, &mTid)){
free(pResult);
}
?
// 3.顯示初始化
    screen.screen_width = SCREEN_WIDTH;
    screen.screen_height = SCREEN_HEIGHT;
    screen.wins[0].enable = 1;
    screen.wins[0].in_fmt = IMAGE_TYPE_RGB888;
    screen.wins[0].in_w = CAMERA_WIDTH;
    screen.wins[0].in_h = CAMERA_HEIGHT;
    screen.wins[0].rotation = 90;
    screen.wins[0].win_x = 0;
    screen.wins[0].win_y = 0;
    screen.wins[0].win_w = 720;
    screen.wins[0].win_h = 1280;
    ret = disp_init_pro(&screen);
if (ret) {
printf("error: %s, %dn", __func__, __LINE__);
goto exit_free_all;
}
    
// 4.(取流 + 顯示)循環
while(1)
    {
// 4.1、取流
pthread_mutex_lock(&img_lock);
ret = usbcamera_getframe(USB2_0, USB_DIRECT, pRGBbuf);
        if (0 != rgbRet) 
        {
            printf("error: %s, %dn", __func__, __LINE__);
pthread_mutex_unlock(&img_lock);
            continue;
        }
algorithm_image = Mat(CAMERA_HEIGHT, CAMERA_WIDTH, CV_8UC3, pRGBbuf);
image = algorithm_image.clone();
pthread_mutex_unlock(&img_lock);
?
// 4.2、顯示
        if (pResult->bHasFace) //檢測到人臉
        {
            Scalar color;
            //識別到已注冊的人臉
            if(pResult->bMatch)
            {
                color = COLOR_GREEN;
                cv::putText(image, std::string("idStr: ") + std::string(pResult->idStr), cv::Point2f(30, 50), cv::FONT_HERSHEY_SIMPLEX, 1.45, CV_RGB(255,0,0),3.0);
                cv::putText(image, std::string("name: ") + std::string(pResult->nameStr), cv::Point2f(30, 100), cv::FONT_HERSHEY_SIMPLEX, 1.45, CV_RGB(255,0,0),3.0);
                cv::putText(image, std::string("similarity: ") + std::to_string(pResult->similarity), cv::Point2f(30, 150), cv::FONT_HERSHEY_SIMPLEX, 1.45, CV_RGB(255,0,0),3.0);
                cv::putText(image, std::string("use time: ") + std::to_string(pResult->useTime), cv::Point2f(30, 200), cv::FONT_HERSHEY_SIMPLEX, 1.45, CV_RGB(255,0,0),3.0);
            }
            else
            {
                color = COLOR_RED;
                cv::putText(image, std::string("unknow face"), cv::Point2f(30, 50), cv::FONT_HERSHEY_SIMPLEX, 1.45, CV_RGB(0,0,255),3.0);
            }
            // 畫框
            rectangle(image, Point(pResult->x1, pResult->y1), Point(pResult->x2, pResult->y2), color, 3);
        }
        disp_commit(image.data, IMAGE_SIZE);

        usleep(20*1000);
}
?
exit_free_all:
pthread_mutex_destroy(&img_lock);
exit_freeusb_freebuf:
free(pRGBbuf);
pRGBbuf = NULL;
exit_freeusb:
usbcamera_exit(USB2_0, USB_DIRECT);
exit_donothing:
    return ret;
}

2.2 人臉識別處理

去掉紅外攝像頭的活體檢測邏輯,只使用USB攝像頭的圖像進行人臉識別
2.png

void *detect_thread_entry(void *para)
{
int ret;
uint64_t start_time,end_time;
Result_t *pResult = (Result_t *)para;
    
// 初始化人臉檢測
rknn_context detect_ctx;
std::vector detect_result;
Point2f points[5];
    s32Rect_t rgbRect;
printf("face detect init!n");
ret = face_detect_init(&detect_ctx, "./face_detect.model");
if( ret < 0)
    {
printf("face_detect fail! ret=%dn", ret);
return NULL;
}
    
// 初始化人臉識別
rknn_context recognition_ctx;
float face_feature[512];
printf("face recognition init!n");
ret =  face_recognition_init(&recognition_ctx, "./face_recognition.model");
if( ret < 0)
    {
printf("face_recognition fail! ret=%dn", ret);
return NULL;
}
?
    // 初始化數據庫
    database_init();
    // 同步數據庫所有數據到內存
faceData_t *pFaceData = (faceData_t *)malloc(MAX_USER_NUM * sizeof(faceData_t));
    memset(pFaceData, 0, MAX_USER_NUM * sizeof(faceData_t));
    int peopleNum = database_getData_to_memory(pFaceData);

// 初始化按鍵事件
keyEvent_init();
set_event_handle(dataBase_opt_handle);
    
Mat image;
Mat face_algin;
float similarity; //特征值相似度比對
int face_index = 0;
while(1)
{
if(g_delete_all_record)
        {
g_delete_all_record = false;
// 刪除庫
database_delete_all_record();
// 重載數據庫
peopleNum = database_getData_to_memory(pFaceData);
}

        if(algorithm_image.empty()) 
        {
usleep(5);
            continue;
        }

pthread_mutex_lock(&img_lock);
image = algorithm_image.clone();
pthread_mutex_unlock(&img_lock);
        
// 人臉檢測,計算出人臉位置
ret = face_detect_run(detect_ctx, image, detect_result);
if(ret <= 0)
        {
// 識別結果數據,復位
memset(pResult, 0 , sizeof(Result_t));
g_input_feature = false;
usleep(1000);
continue;
}
        
        
        rgbRect.left   = (uint32_t)(detect_result[0].box.x);
        rgbRect.top    = (uint32_t)(detect_result[0].box.y);
        rgbRect.right  = (uint32_t)(detect_result[0].box.x + detect_result[0].box.width);
        rgbRect.bottom = (uint32_t)(detect_result[0].box.y + detect_result[0].box.height);
pResult->bHasFace = true;
pResult->x1 = rgbRect.left;
pResult->y1 = rgbRect.top;
pResult->x2 = rgbRect.right;
pResult->y2 = rgbRect.bottom;
for (int i = 0; i < (int)detect_result[0].landmarks.size(); ++i) {
points[i].x = (int)detect_result[0].landmarks[i].x;
points[i].y = (int)detect_result[0].landmarks[i].y;
}
        
// 人臉校正(從圖像中裁出人臉)
face_algin = face_alignment(image, points);
        
// 人臉識別,計算特征值
start_time = get_timeval_ms();
face_recognition_run(recognition_ctx, &face_algin, &face_feature);
end_time = get_timeval_ms();
        pResult->useTime = end_time - start_time;
printf("n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>n");
printf("face_recognition_run use time: %llun", pResult->useTime); // 【打印耗時】
        
        // 特征值比對,得出id
similarity = -0.5;
if(peopleNum > 0)
        {
for(face_index = 0; face_index < peopleNum; ++face_index)
            {
similarity = face_recognition_comparison(face_feature, (float *)((pFaceData + face_index)->feature), 512);
if(similarity > 0.5) 
                {
                    break;
                }
}
}
        pResult->similarity = similarity;
printf("similarity:%fn", similarity); //【打印得分】
if((face_index < peopleNum)&&(similarity > 0.5))
        {
            pResult->bMatch = true;
            
// 用id,找名字
            memcpy(pResult->idStr, (pFaceData + face_index)->id, 128);
printf("idStr : %sn", pResult->idStr); //【打印id】
database_id_is_exist(pResult->idStr, pResult->nameStr, sizeof(pResult->nameStr));
printf("person name : %sn", pResult->nameStr); //【打印名字】

            // 按鍵被按下,更新特征值
if(g_input_feature)
            {
g_input_feature = false;
// 特征值入庫
database_add_record(pResult->idStr, pResult->nameStr, (char *)face_feature, sizeof(face_feature));
// 重載數據庫
peopleNum = database_getData_to_memory(pFaceData);
}
}
        else
        {
            pResult->bMatch = false;
            
// 按鍵被按下,錄入特征值
if(g_input_feature)
            {
g_input_feature = false;
char idStr[32]={0};
char nameStr[32]={0};
sprintf(idStr, "%05d", face_index+1);
sprintf(nameStr, "people_%d", face_index+1);
// 特征值入庫
database_add_record(idStr, nameStr, (char *)face_feature, sizeof(face_feature));
// 重載數據庫
peopleNum = database_getData_to_memory(pFaceData);
}
}
        usleep(16*1000);
}

/* 數據庫內存數據釋放 */
free(pFaceData);
/* 數據庫釋放 */
    database_exit();
/* 人臉識別釋放 */
face_recognition_release(recognition_ctx);
/* 人臉檢測釋放 */
face_detect_release(detect_ctx);
return NULL;
}

3 測試

測試視頻見文章底部視頻,這里再放一張測試圖片:
3.png

4 總結

本篇介紹了EASY EAI Nano的人臉識別功能,與上篇的人臉檢測相比,在檢測到有人臉的基礎上,通過先錄入人臉顯示到數據庫,可以對比當前識別的誰的臉,實際測試,去掉活體檢測功能后,通過外接USB攝像頭來識別電腦屏幕上的3個人的多張不同人臉,可以分辨出不同人的人臉。


-----------



附上EASY EAI Nano多人臉識別測試【視頻】,詳見作者原帖子內容。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • AI
    AI
    +關注

    關注

    87

    文章

    34063

    瀏覽量

    275188
  • 人臉識別
    +關注

    關注

    76

    文章

    4068

    瀏覽量

    83602
  • 靈眸
    +關注

    關注

    0

    文章

    19

    瀏覽量

    3278
收藏 人收藏

    評論

    相關推薦
    熱點推薦

    無需接線!1個底板可測試海凌科5人臉識別模塊

    買一個人臉識別模塊就要買不同的測試底板?試用一款新的人臉識別模塊,每次都要重新接線?海凌科通用型
    的頭像 發表于 05-12 12:06 ?133次閱讀
    無需接線!1個底板可<b class='flag-5'>測試</b>海凌科<b class='flag-5'>5</b>款<b class='flag-5'>人臉</b><b class='flag-5'>識別</b>模塊

    基于RK3576開發板的遠程桌面調試方法

    EASY EAI Orin-Nano可以基于MobaXterm的ssh遠程桌面登錄調試
    的頭像 發表于 05-06 09:58 ?111次閱讀
    基于RK3576開發板的遠程桌面調試方法

    意法半導體邊緣AI套件中提供的全部工具

    意法半導體邊緣AI套件(ST Edge AI Suite)是一套專為邊緣AI開發設計的集成化工具集合,覆蓋從數據采集、模型優化到硬件部署的全流程。以下是該
    的頭像 發表于 04-21 17:46 ?414次閱讀

    基于RV1126開發板的resnet50訓練部署教程

    本教程基于圖像分類算法ResNet50的訓練和部署到EASY-EAI-Nano(RV1126)進行說明
    的頭像 發表于 04-18 15:07 ?298次閱讀
    基于RV1126開發板的resnet50訓練部署教程

    基于RV1126開發板的啟動Logo更換方法

    EASY EAI Nano固件內擁有2個logo,分別用于uboot階段顯示,以及kernel(內核)階段顯示。
    的頭像 發表于 04-15 10:36 ?175次閱讀
    基于RV1126開發板的啟動Logo更換方法

    首創開源架構,天璣AI開發套件讓端側AI模型接入得心應手

    MDDC 2025,聯發科不僅帶來了更加強大、全面的開發者解決方案,更展示了不斷拓展的天璣AI生態。從去年MDDC 2024之后,天璣AI生態伙伴數量大幅增長了3倍,天璣AI開發套件
    發表于 04-13 19:52

    RK3576 yolov8訓練部署教程

    本章展示yolov8模型的在EASY EAI Orin nano的部署過程。
    的頭像 發表于 04-02 16:04 ?290次閱讀
    RK3576 yolov8訓練部署教程

    【幸狐Omni3576邊緣計算套件試用體驗】人臉識別

    【幸狐Omni3576邊緣計算套件試用體驗】人臉識別 本文介紹了幸狐 Omni3576 邊緣計算套件結合 Retinaface 算法實現
    發表于 04-01 21:46

    《DNESP32S3使用指南-IDF版_V1.6》第五十九章 人臉識別實驗

    識別的一系列相關技術。本章,我們使用樂鑫AI庫來實現人臉識別功能。本章分為如下幾個部分:59.1 硬件設計59.2 軟件設計59.3 下載驗
    發表于 03-26 09:40

    安信可AI人臉識別方案

    作為神仙世界的高科技,"無接觸式開鎖",人臉識別技術也被廣泛應用在現代生活中,安信可也有AI人臉識別方案!
    的頭像 發表于 02-25 14:39 ?321次閱讀
    安信可<b class='flag-5'>AI</b><b class='flag-5'>人臉</b><b class='flag-5'>識別</b>方案

    NVIDIA發布小巧高性價比的Jetson Orin Nano Super開發者套件

    Nano Super開發者套件體積小巧,僅相當于一個手掌大小,但其功能卻異常強大。該套件旨在為商業AI開發者、科技愛好者以及學生等各類用戶
    的頭像 發表于 12-19 11:28 ?965次閱讀

    基于迅為RK3568/RK3588開發板的AI圖像識別方案

    01_官方模型測試 02_人臉識別 03_口罩檢測 04_工地防護 05_撲克牌識別 06_手掌關鍵點檢測 07_人臉特征點檢測
    發表于 08-28 09:50

    基于迅為RK3588開發板的AI圖像識別方案

    迅為RK3568/RK3588開發板AI識別演示方案包括 01_官方模型測試 02_人臉識別 03_口罩檢測 04_工地防護 05_撲克牌
    發表于 08-13 11:26

    人臉識別技術的原理介紹

    人臉識別技術是一種基于人臉特征信息進行身份識別的生物識別技術。它通過分析人臉圖像,提取
    的頭像 發表于 07-04 09:22 ?2487次閱讀

    人臉識別模型訓練是什么意思

    人臉識別模型訓練是指通過大量的人臉數據,使用機器學習或深度學習算法,訓練出一個能夠識別和分類人臉的模型。這個模型可以應用于各種場景,如安防監
    的頭像 發表于 07-04 09:16 ?1165次閱讀
    主站蜘蛛池模板: www国产永久免费视频看看 | 欧美1区 | 亚洲主播自拍 | 天天玩天天操 | 永久免费av网站 | 欧美性色欧美a在线观看 | a级毛片免费网站 | 欧美一卡二卡3卡4卡无卡六卡七卡科普 | 国产理论片在线观看 | 在线天堂中文有限公司 | 欲色影视 | 日韩特黄毛片 | 欧美性喷潮 | 三级色图| 五月天婷婷视频在线观看 | 日本亚洲卡一卡2卡二卡三卡四卡 | 中文字幕在线观看你懂的 | 波多野结衣久久精品 | www.黄网| 在线二区 | 天天做天天爱夜夜爽毛片毛片 | 亚洲qingse中文久久网 | 轻点灬大ji巴太粗太长了啊h | 99r8这里精品热视频免费看 | 四虎成人在线视频 | 午夜快播| 男男全肉高h腐文 | 亚洲天堂一区二区三区 | 天天在线免费视频 | 免费网站看av片 | 欧美午夜影视 | 丁香六月色婷婷 | 91操视频 | 黄色a网站| 亚洲qingse中文久久网 | 亚洲欧洲精品成人久久曰影片 | 日韩黄页| 一色屋成人免费精品网站 | 欧美网站免费 | 亚洲国产精品自在现线让你爽 | 影音先锋在线亚洲精品推荐 |