人臉姿態估計

2021-07-31 23:57:12 字數 4517 閱讀 6605

由於需要在採集的集中選擇與待識別人臉姿態最接近的與之進行對比,因此考慮使用人臉姿態估計計算人臉在三維空間的角度,然後找出與之最接近的角度。

在網上查閱資料發現大多都是演算法介紹,缺少原始碼,最終在github上找到乙個基於dlib68點檢測和opencv計算角度的專案<< head-pose-estimation>>,感謝lincolnhard。

在此貼出計算一張人臉姿態的**。

facepose_estimation.cpp:

#include 

#include

#include

#include

#include

#include

using

namespace dlib;

using

namespace

std;

//intrisics can be calculated using opencv sample code under opencv/sources/samples/cpp/tutorial_code/calib3d

double k[9] = ;

double d[5] = ;

int main()

//fill in 2d ref points, annotations follow

image_pts.push_back(cv::point2d(shape.part(17).x(), shape.part(17).y())); //#17 left brow left corner

image_pts.push_back(cv::point2d(shape.part(21).x(), shape.part(21).y())); //#21 left brow right corner

image_pts.push_back(cv::point2d(shape.part(22).x(), shape.part(22).y())); //#22 right brow left corner

image_pts.push_back(cv::point2d(shape.part(26).x(), shape.part(26).y())); //#26 right brow right corner

image_pts.push_back(cv::point2d(shape.part(36).x(), shape.part(36).y())); //#36 left eye left corner

image_pts.push_back(cv::point2d(shape.part(39).x(), shape.part(39).y())); //#39 left eye right corner

image_pts.push_back(cv::point2d(shape.part(42).x(), shape.part(42).y())); //#42 right eye left corner

image_pts.push_back(cv::point2d(shape.part(45).x(), shape.part(45).y())); //#45 right eye right corner

image_pts.push_back(cv::point2d(shape.part(31).x(), shape.part(31).y())); //#31 nose left corner

image_pts.push_back(cv::point2d(shape.part(35).x(), shape.part(35).y())); //#35 nose right corner

image_pts.push_back(cv::point2d(shape.part(48).x(), shape.part(48).y())); //#48 mouth left corner

image_pts.push_back(cv::point2d(shape.part(54).x(), shape.part(54).y())); //#54 mouth right corner

image_pts.push_back(cv::point2d(shape.part(57).x(), shape.part(57).y())); //#57 mouth central bottom corner

image_pts.push_back(cv::point2d(shape.part(8).x(), shape.part(8).y())); //#8 chin corner

//calc pose

cv::solvepnp(object_pts, image_pts, cam_matrix, dist_coeffs, rotation_vec, translation_vec);

//reproject

cv::projectpoints(reprojectsrc, rotation_vec, translation_vec, cam_matrix, dist_coeffs, reprojectdst);

//draw axis

line(temp, reprojectdst[0], reprojectdst[1], cv::scalar(0, 0, 255));

line(temp, reprojectdst[1], reprojectdst[2], cv::scalar(0, 0, 255));

line(temp, reprojectdst[2], reprojectdst[3], cv::scalar(0, 0, 255));

line(temp, reprojectdst[3], reprojectdst[0], cv::scalar(0, 0, 255));

line(temp, reprojectdst[4], reprojectdst[5], cv::scalar(0, 0, 255));

line(temp, reprojectdst[5], reprojectdst[6], cv::scalar(0, 0, 255));

line(temp, reprojectdst[6], reprojectdst[7], cv::scalar(0, 0, 255));

line(temp, reprojectdst[7], reprojectdst[4], cv::scalar(0, 0, 255));

line(temp, reprojectdst[0], reprojectdst[4], cv::scalar(0, 0, 255));

line(temp, reprojectdst[1], reprojectdst[5], cv::scalar(0, 0, 255));

line(temp, reprojectdst[2], reprojectdst[6], cv::scalar(0, 0, 255));

line(temp, reprojectdst[3], reprojectdst[7], cv::scalar(0, 0, 255));

//calc euler angle

cv::rodrigues(rotation_vec, rotation_mat);

cv::hconcat(rotation_mat, translation_vec, pose_mat);

cv::decomposeprojectionmatrix(pose_mat, out_intrinsics, out_rotation, out_translation, cv::noarray(), cv::noarray(), cv::noarray(), euler_angle);

//show angle result

outtext << "x: "

<< setprecision(3) << euler_angle.at(0);

cv::puttext(temp, outtext.str(), cv::point(50, 40), cv::font_hershey_******x, 0.75, cv::scalar(0, 255, 0));

outtext.str("");

outtext << "y: "

<< setprecision(3) << euler_angle.at(1);

cv::puttext(temp, outtext.str(), cv::point(50, 60), cv::font_hershey_******x, 0.75, cv::scalar(0, 255, 0));

outtext.str("");

outtext << "z: "

<< setprecision(3) << euler_angle.at(2);

cv::puttext(temp, outtext.str(), cv::point(50, 80), cv::font_hershey_******x, 0.75, cv::scalar(0, 255, 0));

outtext.str("");

image_pts.clear();

}imshow("demo", temp);

cvwaitkey(0);

return

0;}

標記姿態估計

在三維空間中,可通過標記角點的精確位置來估計攝像機與標記之間的變換。此操作稱為二維到三維的姿態估計。該估計過程會在物體與攝像機之間找到乙個歐氏空間的變換 該變換僅由旋轉和座標平移構成 先來觀察右圖 圖中的c表示攝像機中心,點p1 p4是現實座標系中的三維點,而p1 p4是將點p1 p4投影到攝像機的...

頭部姿態估計

通常認為人體頭部可以建模為乙個無實體的剛體物件。根據這種假設,在姿勢上人類的頭部被限制為3個自由度,其特徵分別是俯仰,坡度和偏航角在下圖中體現。人臉姿態估計,顧名思義,給定一張人臉影象,確定其姿態,姿態由什麼構成呢?很簡單 pitch,yaw,roll 三種角度,分別代表上下翻轉,左右翻轉,平面內旋...

姿態估計 Hourglass 網路

本文是 eccv2016 的工作,主要是介紹了乙個在當時是新的姿態估計的網路結構。這裡主要是對整個網路的結構和思想進行乙個梳理,可以進一步明白後序一些基於此網路結構的工作 例如eccv2018 cornernet 不涉及到 姿態估計領域 的一些見解和討論,所以本文主要就是分為兩節,引出課題和介紹 h...