add symmetric color style option

PiperOrigin-RevId: 547069284
This commit is contained in:
MediaPipe Team 2023-07-10 21:39:22 -07:00 committed by Copybara-Service
parent 0bde987a38
commit bf6561ce91
3 changed files with 36 additions and 12 deletions

View File

@ -152,6 +152,7 @@ cc_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//mediapipe/framework/formats:landmark_cc_proto", "//mediapipe/framework/formats:landmark_cc_proto",
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_core",
"//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:opencv_imgproc",
], ],

View File

@ -1,5 +1,6 @@
#include "mediapipe/util/pose_util.h" #include "mediapipe/util/pose_util.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/opencv_imgproc_inc.h" #include "mediapipe/framework/port/opencv_imgproc_inc.h"
namespace { namespace {
@ -192,7 +193,7 @@ void DrawPose(const mediapipe::NormalizedLandmarkList& pose, bool flip_y,
} }
void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y, void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y,
bool draw_nose, bool color_style, bool reverse_color, bool draw_nose, int color_style, bool reverse_color,
int draw_line_width, cv::Mat* image) { int draw_line_width, cv::Mat* image) {
const int target_width = image->cols; const int target_width = image->cols;
const int target_height = image->rows; const int target_height = image->rows;
@ -202,16 +203,26 @@ void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y,
(flip_y ? 1.0f - lm.y() : lm.y()) * target_height); (flip_y ? 1.0f - lm.y() : lm.y()) * target_height);
} }
cv::Scalar kFaceOvalColor = kWhiteColor; cv::Scalar kFaceOvalColor;
cv::Scalar kLipsColor = kWhiteColor; cv::Scalar kLipsColor;
cv::Scalar kLeftEyeColor = kGreenColor; cv::Scalar kLeftEyeColor;
cv::Scalar kLeftEyebrowColor = kGreenColor; cv::Scalar kLeftEyebrowColor;
cv::Scalar kLeftEyeIrisColor = kGreenColor; cv::Scalar kLeftEyeIrisColor;
cv::Scalar kRightEyeColor = kRedColor; cv::Scalar kRightEyeColor;
cv::Scalar kRightEyebrowColor = kRedColor; cv::Scalar kRightEyebrowColor;
cv::Scalar kRightEyeIrisColor = kRedColor; cv::Scalar kRightEyeIrisColor;
cv::Scalar kNoseColor = kWhiteColor; cv::Scalar kNoseColor;
if (color_style) { if (color_style == 0) {
kFaceOvalColor = kWhiteColor;
kLipsColor = kWhiteColor;
kLeftEyeColor = kGreenColor;
kLeftEyebrowColor = kGreenColor;
kLeftEyeIrisColor = kGreenColor;
kRightEyeColor = kRedColor;
kRightEyebrowColor = kRedColor;
kRightEyeIrisColor = kRedColor;
kNoseColor = kWhiteColor;
} else if (color_style == 1) {
kFaceOvalColor = kWhiteColor; kFaceOvalColor = kWhiteColor;
kLipsColor = kBlueColor; kLipsColor = kBlueColor;
kLeftEyeColor = kCyanColor; kLeftEyeColor = kCyanColor;
@ -221,6 +232,18 @@ void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y,
kRightEyebrowColor = kRedColor; kRightEyebrowColor = kRedColor;
kRightEyeIrisColor = kRedColor; kRightEyeIrisColor = kRedColor;
kNoseColor = kYellowColor; kNoseColor = kYellowColor;
} else if (color_style == 2) {
kFaceOvalColor = kWhiteColor;
kLipsColor = kBlueColor;
kLeftEyeColor = kCyanColor;
kLeftEyebrowColor = kGreenColor;
kLeftEyeIrisColor = kRedColor;
kRightEyeColor = kCyanColor;
kRightEyebrowColor = kGreenColor;
kRightEyeIrisColor = kRedColor;
kNoseColor = kYellowColor;
} else {
LOG(ERROR) << "color_style not supported.";
} }
if (reverse_color) { if (reverse_color) {

View File

@ -24,7 +24,7 @@ void DrawPose(const mediapipe::NormalizedLandmarkList& pose, bool flip_y,
cv::Mat* image); cv::Mat* image);
void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y, void DrawFace(const mediapipe::NormalizedLandmarkList& face, bool flip_y,
bool draw_nose, bool color_style, bool reverse_color, bool draw_nose, int color_style, bool reverse_color,
int draw_line_width, cv::Mat* image); int draw_line_width, cv::Mat* image);
} // namespace mediapipe } // namespace mediapipe