add face renderer for adapter
PiperOrigin-RevId: 524148938
This commit is contained in:
parent
f712eed6c3
commit
18ef79ac9f
|
@ -66,11 +66,54 @@ const int kConnectionColorMap[35][3] = {
|
||||||
{127, 127, 151}, {0, 255, 141}, {255, 0, 160}, {3, 255, 50},
|
{127, 127, 151}, {0, 255, 141}, {255, 0, 160}, {3, 255, 50},
|
||||||
{231, 0, 231}, {51, 255, 3}, {159, 0, 255}, {143, 255, 0},
|
{231, 0, 231}, {51, 255, 3}, {159, 0, 255}, {143, 255, 0},
|
||||||
{67, 0, 255}, {98, 255, 3}, {115, 0, 255}};
|
{67, 0, 255}, {98, 255, 3}, {115, 0, 255}};
|
||||||
|
|
||||||
|
const int kFaceMeshLips[40][2] = {
|
||||||
|
{61, 146}, {146, 91}, {91, 181}, {181, 84}, {84, 17}, {17, 314},
|
||||||
|
{314, 405}, {405, 321}, {321, 375}, {375, 291}, {61, 185}, {185, 40},
|
||||||
|
{40, 39}, {39, 37}, {37, 0}, {0, 267}, {267, 269}, {269, 270},
|
||||||
|
{270, 409}, {409, 291}, {78, 95}, {95, 88}, {88, 178}, {178, 87},
|
||||||
|
{87, 14}, {14, 317}, {317, 402}, {402, 318}, {318, 324}, {324, 308},
|
||||||
|
{78, 191}, {191, 80}, {80, 81}, {81, 82}, {82, 13}, {13, 312},
|
||||||
|
{312, 311}, {311, 310}, {310, 415}, {415, 308}};
|
||||||
|
|
||||||
|
const int kFaceMeshLeftEye[16][2] = {
|
||||||
|
{263, 249}, {249, 390}, {390, 373}, {373, 374}, {374, 380}, {380, 381},
|
||||||
|
{381, 382}, {382, 362}, {263, 466}, {466, 388}, {388, 387}, {387, 386},
|
||||||
|
{386, 385}, {385, 384}, {384, 398}, {398, 362}};
|
||||||
|
|
||||||
|
const int kFaceMeshLeftIris[4][2] = {
|
||||||
|
{474, 475}, {475, 476}, {476, 477}, {477, 474}};
|
||||||
|
|
||||||
|
const int kFaceMeshLeftEyebrow[8][2] = {{276, 283}, {283, 282}, {282, 295},
|
||||||
|
{295, 285}, {300, 293}, {293, 334},
|
||||||
|
{334, 296}, {296, 336}};
|
||||||
|
|
||||||
|
const int kFaceMeshRightEye[16][2] = {
|
||||||
|
{33, 7}, {7, 163}, {163, 144}, {144, 145}, {145, 153}, {153, 154},
|
||||||
|
{154, 155}, {155, 133}, {33, 246}, {246, 161}, {161, 160}, {160, 159},
|
||||||
|
{159, 158}, {158, 157}, {157, 173}, {173, 133}};
|
||||||
|
|
||||||
|
const int kFaceMeshRightEyebrow[8][2] = {{46, 53}, {53, 52}, {52, 65},
|
||||||
|
{65, 55}, {70, 63}, {63, 105},
|
||||||
|
{105, 66}, {66, 107}};
|
||||||
|
|
||||||
|
const int kFaceMeshRightIris[4][2] = {
|
||||||
|
{469, 470}, {470, 471}, {471, 472}, {472, 469}};
|
||||||
|
|
||||||
|
const int kFaceMeshFaceOval[36][2] = {
|
||||||
|
{10, 338}, {338, 297}, {297, 332}, {332, 284}, {284, 251}, {251, 389},
|
||||||
|
{389, 356}, {356, 454}, {454, 323}, {323, 361}, {361, 288}, {288, 397},
|
||||||
|
{397, 365}, {365, 379}, {379, 378}, {378, 400}, {400, 377}, {377, 152},
|
||||||
|
{152, 148}, {148, 176}, {176, 149}, {149, 150}, {150, 136}, {136, 172},
|
||||||
|
{172, 58}, {58, 132}, {132, 93}, {93, 234}, {234, 127}, {127, 162},
|
||||||
|
{162, 21}, {21, 54}, {54, 103}, {103, 67}, {67, 109}, {109, 10}};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace mediapipe {
|
namespace mediapipe {
|
||||||
void DrawPose(const mediapipe::NormalizedLandmarkList& pose, int target_width,
|
void DrawPose(const mediapipe::NormalizedLandmarkList& pose, bool flip_y,
|
||||||
int target_height, bool flip_y, cv::Mat* image) {
|
cv::Mat* image) {
|
||||||
|
const int target_width = image->cols;
|
||||||
|
const int target_height = image->rows;
|
||||||
constexpr float kVisThres = 0.4f;
|
constexpr float kVisThres = 0.4f;
|
||||||
constexpr float kPresThres = 0.4f;
|
constexpr float kPresThres = 0.4f;
|
||||||
std::map<int, cv::Point> visible_landmarks;
|
std::map<int, cv::Point> visible_landmarks;
|
||||||
|
@ -124,4 +167,63 @@ void DrawPose(const mediapipe::NormalizedLandmarkList& pose, int target_width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y,
|
||||||
|
cv::Mat* image) {
|
||||||
|
const int target_width = image->cols;
|
||||||
|
const int target_height = image->rows;
|
||||||
|
std::vector<cv::Point> landmarks;
|
||||||
|
for (const auto& lm : face.landmark()) {
|
||||||
|
landmarks.emplace_back(lm.x() * target_width,
|
||||||
|
(flip_y ? 1.0f - lm.y() : lm.y()) * target_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int draw_line_width = 2;
|
||||||
|
for (int j = 0; j < 36; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshFaceOval[j][0]],
|
||||||
|
landmarks[kFaceMeshFaceOval[j][1]], cv::Scalar(224, 224, 224),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 40; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshLips[j][0]],
|
||||||
|
landmarks[kFaceMeshLips[j][1]], cv::Scalar(224, 224, 224),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 16; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshLeftEye[j][0]],
|
||||||
|
landmarks[kFaceMeshLeftEye[j][1]], cv::Scalar(48, 255, 48),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshLeftEyebrow[j][0]],
|
||||||
|
landmarks[kFaceMeshLeftEyebrow[j][1]], cv::Scalar(48, 255, 48),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshLeftIris[j][0]],
|
||||||
|
landmarks[kFaceMeshLeftIris[j][1]], cv::Scalar(48, 255, 48),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 16; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshRightEye[j][0]],
|
||||||
|
landmarks[kFaceMeshRightEye[j][1]], cv::Scalar(48, 48, 255),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshRightEyebrow[j][0]],
|
||||||
|
landmarks[kFaceMeshRightEyebrow[j][1]], cv::Scalar(48, 48, 255),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; ++j) {
|
||||||
|
cv::line(*image, landmarks[kFaceMeshRightIris[j][0]],
|
||||||
|
landmarks[kFaceMeshRightIris[j][1]], cv::Scalar(48, 48, 255),
|
||||||
|
draw_line_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace mediapipe
|
} // namespace mediapipe
|
||||||
|
|
|
@ -20,8 +20,11 @@
|
||||||
|
|
||||||
namespace mediapipe {
|
namespace mediapipe {
|
||||||
|
|
||||||
void DrawPose(const mediapipe::NormalizedLandmarkList& pose, int target_width,
|
void DrawPose(const mediapipe::NormalizedLandmarkList& pose, bool flip_y,
|
||||||
int target_height, bool flip_y, cv::Mat* image);
|
cv::Mat* image);
|
||||||
|
|
||||||
|
void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y,
|
||||||
|
cv::Mat* image);
|
||||||
|
|
||||||
} // namespace mediapipe
|
} // namespace mediapipe
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user