女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

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

3天內(nèi)不再提示

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

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

本文來源電子發(fā)燒友社區(qū),作者:碼農(nóng)愛學(xué)習, 帖子地址: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介紹

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

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

face_recognition.h的主要內(nèi)容

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

一些參數(shù):

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

face_alignment.h的主要內(nèi)容

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

geometry.h的主要內(nèi)容

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;
?
//判斷點是否在矩形內(nèi)
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攝像頭,另外,識別結(jié)果的顯示,將更多的信息(識別的id,人物名稱,耗時等)展示在屏幕上。

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

重新定義識別結(jié)果:

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圖像進行人臉識別。

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

#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.創(chuàng)建識別線程,以及圖像互斥鎖
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.(取流 + 顯示)循環(huán)
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;
}
?
    // 初始化數(shù)據(jù)庫
    database_init();
    // 同步數(shù)據(jù)庫所有數(shù)據(jù)到內(nèi)存
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();
// 重載數(shù)據(jù)庫
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)
        {
// 識別結(jié)果數(shù)據(jù),復(fù)位
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));
// 重載數(shù)據(jù)庫
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));
// 重載數(shù)據(jù)庫
peopleNum = database_getData_to_memory(pFaceData);
}
}
        usleep(16*1000);
}

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

3 測試

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

4 總結(jié)

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


-----------



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

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

    關(guān)注

    87

    文章

    34294

    瀏覽量

    275471
  • 人臉識別
    +關(guān)注

    關(guān)注

    76

    文章

    4070

    瀏覽量

    83695
  • 靈眸
    +關(guān)注

    關(guān)注

    0

    文章

    20

    瀏覽量

    3283
收藏 人收藏

    評論

    相關(guān)推薦
    熱點推薦

    基于RK3576處理器,EASY EAI Orin Nano開發(fā)板免費試用

    EASY EAI Orin Nano是廣州靈眸科技有限公司的旗艦級硬件產(chǎn)品。基于瑞芯微的RK3576處理器設(shè)計,集成了4個Cortex-A72和4個Cortex-A53及支持NEON指令集,支持
    的頭像 發(fā)表于 06-09 15:01 ?128次閱讀
    基于RK3576處理器,<b class='flag-5'>EASY</b> <b class='flag-5'>EAI</b> Orin <b class='flag-5'>Nano</b>開發(fā)板免費<b class='flag-5'>試用</b>

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

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

    基于RK3576開發(fā)板的遠程桌面調(diào)試方法

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

    意法半導(dǎo)體邊緣AI套件中提供的全部工具

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

    基于RV1126開發(fā)板的resnet50訓(xùn)練部署教程

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

    基于RV1126開發(fā)板的啟動Logo更換方法

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

    首創(chuàng)開源架構(gòu),天璣AI開發(fā)套件讓端側(cè)AI模型接入得心應(yīng)手

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

    RK3576 yolov8訓(xùn)練部署教程

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

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

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

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

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

    安信可AI人臉識別方案

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

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

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

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

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

    人臉識別技術(shù)的原理介紹

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

    人臉識別模型訓(xùn)練是什么意思

    人臉識別模型訓(xùn)練是指通過大量的人臉數(shù)據(jù),使用機器學(xué)習或深度學(xué)習算法,訓(xùn)練出一個能夠識別和分類人臉的模型。這個模型可以應(yīng)用于各種場景,如安防監(jiān)
    的頭像 發(fā)表于 07-04 09:16 ?1211次閱讀