update face drawing function.

PiperOrigin-RevId: 542083042
This commit is contained in:
MediaPipe Team 2023-06-20 16:31:48 -07:00 committed by Copybara-Service
parent ef6aeb8828
commit 0b6ff84e3c
2 changed files with 22 additions and 4 deletions

View File

@ -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<cv::Point> 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,

View File

@ -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