1. 人臉姿態(tài)估計(jì)簡(jiǎn)介
人臉姿態(tài)估計(jì)是通過(guò)對(duì)一張人臉圖像進(jìn)行分析,獲得臉部朝向的角度信息。姿態(tài)估計(jì)是多姿態(tài)問(wèn)題中較為關(guān)鍵的步驟。一般可以用旋轉(zhuǎn)矩陣、旋轉(zhuǎn)向量、四元數(shù)或歐拉角表示。人臉的姿態(tài)變化通常包括上下俯仰(pitch)、左右旋轉(zhuǎn)(yaw)以及平面內(nèi)角度旋轉(zhuǎn)(roll)。因此,姿態(tài)估計(jì)在多姿態(tài)人臉的識(shí)別和司機(jī)行為檢測(cè)等應(yīng)用場(chǎng)景,具有巨大的現(xiàn)實(shí)意義和實(shí)用價(jià)值。
基于EASY-EAI-Nano硬件主板的運(yùn)行效率:
算法種類 | 運(yùn)行效率 |
face_pose_estimation | 22ms |
2. 快速上手
2.1 開(kāi)發(fā)環(huán)境準(zhǔn)備
如果您初次閱讀此文檔,請(qǐng)閱讀《入門指南/開(kāi)發(fā)環(huán)境準(zhǔn)備/Easy-Eai編譯環(huán)境準(zhǔn)備與更新》,并按照其相關(guān)的操作,進(jìn)行編譯環(huán)境的部署。
在PC端Ubuntu系統(tǒng)中執(zhí)行run腳本,進(jìn)入EASY-EAI編譯環(huán)境,具體如下所示。
cd ~/develop_environment ./run.sh

2.2 源碼下載以及例程編譯
在EASY-EAI編譯環(huán)境下創(chuàng)建存放源碼倉(cāng)庫(kù)的管理目錄:
cd /opt mkdir EASY-EAI-Toolkit cd EASY-EAI-Toolkit
通過(guò)git工具,在管理目錄內(nèi)克隆遠(yuǎn)程倉(cāng)庫(kù)
git clone https://github.com/EASY-EAI/EASY-EAI-Toolkit-C-Demo.git
注:
* 此處可能會(huì)因網(wǎng)絡(luò)原因造成卡頓,請(qǐng)耐心等待。
* 如果實(shí)在要在gitHub網(wǎng)頁(yè)上下載,也要把整個(gè)倉(cāng)庫(kù)下載下來(lái),不能單獨(dú)下載本實(shí)例對(duì)應(yīng)的目錄。
進(jìn)入到對(duì)應(yīng)的例程目錄執(zhí)行編譯操作,具體命令如下所示:
cd EASY-EAI-Toolkit-C-Demo/algorithm-face_pose_estimation/ ./build.sh cpres
注:
* 若build.sh腳本帶有cpres參數(shù),則會(huì)把Release/目錄下的所有資源都拷貝到開(kāi)發(fā)板上。
* 若build.sh腳本不帶任何參數(shù),則僅會(huì)拷貝demo編譯出來(lái)的可執(zhí)行文件。
* 由于依賴庫(kù)部署在板卡上,因此交叉編譯過(guò)程中必須保持adb連接。
2.3 模型部署
要完成算法Demo的執(zhí)行,需要先下載人臉檢測(cè)算法模型。
百度網(wǎng)盤鏈接為:https://pan.baidu.com/s/1cxnx1T0ldJvoqkyTk1RmUg(提取碼:0b6h )。
同時(shí)也要下載人員姿態(tài)估計(jì)算法模型。
百度網(wǎng)盤鏈接為:https://pan.baidu.com/s/1sNZb2X0I7TwdM_n89HI9gg (提取碼:j19k )。
然后需要把下載的人臉檢測(cè)模型和人臉姿態(tài)估計(jì)算法模型復(fù)制粘貼到Release/目錄:
再通過(guò)下方命令將模型署到板卡中,如下所示。
cp ./Release/*.model /mnt/userdata/Demo
2.4 例程運(yùn)行
通過(guò)按鍵Ctrl+Shift+T創(chuàng)建一個(gè)新窗口,執(zhí)行adb shell命令,進(jìn)入板卡運(yùn)行環(huán)境。
adb shell

進(jìn)入板卡后,定位到例程上傳的位置,如下所示:
cd /userdata/Demo
運(yùn)行例程命令如下所示:
./test-face-pose-estimation test-1.jpg
2.5 運(yùn)行效果
face-pose-estimation的Demo執(zhí)行效果如下所示:
再開(kāi)一個(gè)窗口,在PC端Ubuntu環(huán)境通過(guò)以下命令可以把圖片拉回來(lái):
adb pull /userdata/Demo/result.jpg .
結(jié)果圖片如下所示:
API的詳細(xì)說(shuō)明,以及API的調(diào)用(本例程源碼),詳細(xì)信息見(jiàn)下方說(shuō)明。
3. 人臉檢測(cè)API說(shuō)明
3.1 引用方式
為方便客戶在本地工程中直接調(diào)用我們的EASY EAI api庫(kù),此處列出工程中需要鏈接的庫(kù)以及頭文件等,方便用戶直接添加。
選項(xiàng) | 描述 |
頭文件目錄 | easyeai-api/algorithm_api/face_detect |
庫(kù)文件目錄 | easyeai-api/algorithm_api/face_detect |
庫(kù)鏈接參數(shù) | -lpthread -lface_detect -lrknn_api |
3.2 人臉檢測(cè)初始化函數(shù)
設(shè)置人臉檢測(cè)初始化函數(shù)原型如下所示。
int face_detect_init(rknn_context *ctx, const char *path)
具體介紹如下所示。
函數(shù)名: face_detect_init() | |
頭文件 | face_detect.h |
輸入?yún)?shù) | ctx:rknn_context句柄 |
path:算法模型的路徑 | |
返回值 | 成功返回:0 |
失敗返回:-1 | |
注意事項(xiàng) | 無(wú) |
3.3 人臉檢測(cè)運(yùn)行函數(shù)
設(shè)face_detect_run原型如下所示。
int face_detect_run(rknn_context ctx, cv::Mat &input_image, std::vector &result)
具體介紹如下所示。
函數(shù)名: face_detect_run () | |
頭文件 | face_detect.h |
輸入?yún)?shù) |
ctx: rknn_context句柄 |
input_image:Opencv Mat格式圖像 | |
result:人臉檢測(cè)的結(jié)果輸出 | |
返回值 | 成功返回:0 |
失敗返回:-1 | |
注意事項(xiàng) | 無(wú) |
3.4 人臉檢測(cè)釋放函數(shù)
人臉檢測(cè)釋放函數(shù)原型如下所示。
int face_detect_release(rknn_context ctx)
具體介紹如下所示。
函數(shù)名: face_detect_release () | |
頭文件 | face_detect.h |
輸入?yún)?shù) |
ctx: rknn_context句柄 |
返回值 | 成功返回:0 |
失敗返回:-1 | |
注意事項(xiàng) | 無(wú) |
4. 人臉姿態(tài)估計(jì)API說(shuō)明
4.1 引用方式
為方便客戶在本地工程中直接調(diào)用我們的EASY EAI api庫(kù),此處列出工程中需要鏈接的庫(kù)以及頭文件等,方便用戶直接添加。
選項(xiàng) | 描述 |
頭文件目錄 | easyeai-api/algorithm_api/face_pose_estimation |
庫(kù)文件目錄 | easyeai-api/algorithm_api/face_pose_estimation |
庫(kù)鏈接參數(shù) | -lpthread -lface_pose_estimation -lrknn_api |
4.2 人臉姿態(tài)初始化函數(shù)
設(shè)置人臉檢測(cè)初始化函數(shù)原型如下所示。
int face_pose_estimation_init(rknn_context *ctx, const char * path)
具體介紹如下所示。
函數(shù)名: face_pose_estimation_init() | |
頭文件 | face_pose_estimation.h |
輸入?yún)?shù) | ctx:rknn_context句柄 |
path:算法模型的路徑 | |
返回值 | 成功返回:0 |
失敗返回:-1 | |
注意事項(xiàng) | 無(wú) |
4.3 人臉姿態(tài)執(zhí)行函數(shù)
設(shè)face_pose_estimation_run原型如下所示。
int face_pose_estimation_run(rknn_context ctx, cv::Mat *face_image, float *result)
具體介紹如下所示。
函數(shù)名: face_pose_estimation_run () | |
頭文件 | face_pose_estimation.h |
輸入?yún)?shù) |
ctx: rknn_context句柄 |
face_image: 圖像數(shù)據(jù)輸入(cv::Mat是Opencv的類型) | |
result: yaw(偏航角), pitch(俯仰角), roll(翻滾角) | |
返回值 | 成功返回:0 |
失敗返回:-1 | |
注意事項(xiàng) | 無(wú) |
4.4 人臉姿態(tài)釋放函數(shù)
人臉檢測(cè)釋放函數(shù)原型如下所示。
int face_pose_estimation_release(rknn_context ctx)
具體介紹如下所示。
函數(shù)名: face_pose_estimation_release () | |
頭文件 | face_pose_estimation.h |
輸入?yún)?shù) |
ctx: rknn_context句柄 |
返回值 | 成功返回:0 |
失敗返回:-1 | |
注意事項(xiàng) | 無(wú) |
5. 人臉姿態(tài)估計(jì)算法例程
例程目錄為Toolkit-C-Demo/algorithm-face_pose_estimation/test-face-pose-estimation.cpp,操作流程如下。
參考例程如下所示。
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "face_detect.h" #include "face_alignment.h" #include "face_pose_estimation.h" using namespace std; using namespace cv; int plot_one_box(Mat src, int x1, int x2, int y1, int y2, char *label, char colour) { int tl = round(0.002 * (src.rows + src.cols) / 2) + 1; rectangle(src, cv::Point(x1, y1), cv::Point(x2, y2), Scalar(255, 0, 0, 255), 3); int tf = max(tl -1, 1); int base_line = 0; cv::Size t_size = getTextSize(label, FONT_HERSHEY_SIMPLEX, (float)tl/3, tf, &base_line); int x3 = x1 + t_size.width; int y3 = y1 - t_size.height - 3; rectangle(src, cv::Point(x1, y1), cv::Point(x3, y3), Scalar(255, 0, 0, 255), -1); putText(src, label, cv::Point(x1, y1 - 2), FONT_HERSHEY_SIMPLEX, (float)tl/3, cv::Scalar(255, 255, 255, 255), tf, 8); return 0; } int main(int argc, char **argv) { if( argc != 2) { printf("./test-face-pose-estimation xxx.jpg n"); return -1; } rknn_context detect_ctx, face_pose_estimation_ctx; std::vector detect_result; int ret; cv::Mat src; src = cv::imread(argv[1], 1); /* 人臉檢測(cè)初始化 */ ret = face_detect_init(&detect_ctx, "./face_detect.model"); if( ret < 0) { printf("face_detect_init fail! ret=%dn", ret); return -1; } /* 人臉姿態(tài)估計(jì)初始化 */ ret = face_pose_estimation_init(&face_pose_estimation_ctx, "./face_pose_estimation.model"); if( ret < 0) { printf("face_pose_estimation_init fail! ret=%dn", ret); return -1; } /* 人臉檢測(cè)執(zhí)行 */ face_detect_run(detect_ctx, src, detect_result); for( int i=0; i < (int)detect_result.size() ; i++ ) { int x = (int)(detect_result[i].box.x); int y = (int)(detect_result[i].box.y); int w = (int)(detect_result[i].box.width); int h = (int)(detect_result[i].box.height); int max = (w > h)?w:h; // 判斷圖像裁剪是否越界 if( ((x +max) > src.cols) || ((y +max) > src.rows) ) { continue; } cv::Mat roi_img, reize_img, reize_img_rgb; roi_img = src(cv::Rect(x, y, max,max)); roi_img = roi_img.clone(); resize(roi_img, reize_img, Size(224,224), 0, 0, INTER_AREA); cvtColor(reize_img, reize_img_rgb, COLOR_BGR2RGB); /* 人臉姿態(tài)估計(jì)運(yùn)行 */ float pose_result[3]; face_pose_estimation_run(face_pose_estimation_ctx, &reize_img_rgb, pose_result); printf("yaw(偏航角):%f, pitch(俯仰角):%f, roll(翻滾角):%fn", pose_result[0], pose_result[1], pose_result[2]); char label_text[100]; memset(label_text, 0 , sizeof(label_text)); sprintf(label_text, "yaw:%0.2f pitch:%0.2f roll:%0.2f", pose_result[0], pose_result[1], pose_result[2]); plot_one_box(src, x, x+w, y, y+h, label_text, i%10); } imwrite("result.jpg", src); /* 人臉檢測(cè)釋放 */ face_detect_release(detect_ctx); /* 人臉姿態(tài)估計(jì)釋放 */ face_pose_estimation_release(face_pose_estimation_ctx); return 0; } 審核編輯 黃宇
-
算法
+關(guān)注
關(guān)注
23文章
4710瀏覽量
95409 -
開(kāi)發(fā)板
+關(guān)注
關(guān)注
25文章
5682瀏覽量
104840 -
rv1126
+關(guān)注
關(guān)注
0文章
108瀏覽量
3544
發(fā)布評(píng)論請(qǐng)先 登錄
RV1126基于虹軟人臉識(shí)別算法實(shí)現(xiàn)指南
RV1126 38mm主控板數(shù)據(jù)手冊(cè)
RV1126開(kāi)發(fā)板數(shù)據(jù)手冊(cè)
RV1126 實(shí)現(xiàn)人臉檢測(cè)方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉檢測(cè)方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉識(shí)別方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)駕駛員行為檢測(cè)方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉檢測(cè)方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉識(shí)別方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉識(shí)別方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉檢測(cè)方案

基于RV1126開(kāi)發(fā)板實(shí)現(xiàn)人臉檢測(cè)方案

評(píng)論