From 0b6ff84e3c9e211d0d9f664dff3f7f020037ff15 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Tue, 20 Jun 2023 16:31:48 -0700 Subject: [PATCH] update face drawing function. PiperOrigin-RevId: 542083042 --- mediapipe/util/pose_util.cc | 22 ++++++++++++++++++++-- mediapipe/util/pose_util.h | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/mediapipe/util/pose_util.cc b/mediapipe/util/pose_util.cc index 79e3f791f..61663ba55 100644 --- a/mediapipe/util/pose_util.cc +++ b/mediapipe/util/pose_util.cc @@ -125,6 +125,12 @@ const cv::Scalar kPeachColor = cv::Scalar{255, 229, 180}; const cv::Scalar kWhiteColor = cv::Scalar(224, 224, 224); const cv::Scalar kCyanColor = cv::Scalar{48, 255, 192}; const cv::Scalar kMagentaColor = cv::Scalar{255, 48, 192}; + +void ReverseRGB(cv::Scalar* color) { + int tmp = color->val[0]; + color->val[0] = color->val[2]; + color->val[2] = tmp; +} } // namespace namespace mediapipe { @@ -186,8 +192,8 @@ void DrawPose(const mediapipe::NormalizedLandmarkList& pose, bool flip_y, } void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y, - bool draw_nose, bool color_style, int draw_line_width, - cv::Mat* image) { + bool draw_nose, bool color_style, bool reverse_color, + int draw_line_width, cv::Mat* image) { const int target_width = image->cols; const int target_height = image->rows; std::vector landmarks; @@ -217,6 +223,18 @@ void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y, kNoseColor = kYellowColor; } + if (reverse_color) { + ReverseRGB(&kFaceOvalColor); + ReverseRGB(&kLipsColor); + ReverseRGB(&kLeftEyeColor); + ReverseRGB(&kLeftEyebrowColor); + ReverseRGB(&kLeftEyeIrisColor); + ReverseRGB(&kRightEyeColor); + ReverseRGB(&kRightEyebrowColor); + ReverseRGB(&kRightEyeIrisColor); + ReverseRGB(&kNoseColor); + } + for (int j = 0; j < 36; ++j) { cv::line(*image, landmarks[kFaceMeshFaceOval[j][0]], landmarks[kFaceMeshFaceOval[j][1]], kFaceOvalColor, diff --git a/mediapipe/util/pose_util.h b/mediapipe/util/pose_util.h index b4e517187..d94e22cbe 100644 --- a/mediapipe/util/pose_util.h +++ b/mediapipe/util/pose_util.h @@ -24,8 +24,8 @@ void DrawPose(const mediapipe::NormalizedLandmarkList& pose, bool flip_y, cv::Mat* image); void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y, - bool draw_nose, bool color_style, int draw_line_width, - cv::Mat* image); + bool draw_nose, bool color_style, bool reverse_color, + int draw_line_width, cv::Mat* image); } // namespace mediapipe