google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://mediapipe.dev
Apache License 2.0
26.73k stars 5.08k forks source link

Change the color of the face landmarks #4503

Open lxrswdd opened 1 year ago

lxrswdd commented 1 year ago

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

Ubuntu 22.04.2 LTS

MediaPipe Tasks SDK version

No response

Task name (e.g. Image classification, Gesture recognition etc.)

Face Landmarks

Programming Language and version (e.g. C++, Python, Java)

Python 3.10.11

Describe the actual behavior

The color of face landmark remains the default color gray.

Describe the expected behaviour

The color of face landmarks changed.

Standalone code/steps you may have used to try to get what you need

I have access to the source codes of the `/home/guest/anaconda3/envs/smart_class/lib/python3.10/site-packages/mediapipe/python/solutions/drawing_utils.py`

I changed the color of the DrawingSpec Class to blue.

class DrawingSpec:
  # Color for drawing the annotation. Default to the white color.
  color: Tuple[int, int, int] = BLUE_COLOR
  # Thickness for drawing the annotation. Default to 2 pixels.
  thickness: int = 2
  # Circle radius. Default to 2 pixels.
  circle_radius: int = 2

I also changed the color within the draw_landmarks function

  if landmark_drawing_spec:
    for idx, landmark_px in idx_to_coordinates.items():
      drawing_spec = landmark_drawing_spec[idx] if isinstance(
          landmark_drawing_spec, Mapping) else landmark_drawing_spec
      # White circle border
      circle_border_radius = max(drawing_spec.circle_radius + 1,
                                 int(drawing_spec.circle_radius * 1.2))
      cv2.circle(image, landmark_px, circle_border_radius, BLUE_COLOR,
                 drawing_spec.thickness)
      # Fill color into the circle
      cv2.circle(image, landmark_px, drawing_spec.circle_radius,
                 drawing_spec.color, drawing_spec.thickness)

But the color landmarks generated remian gray.



### Other info / Complete Logs

_No response_
kuaashish commented 1 year ago

Hello @lxrswdd,

Sorry for the delayed response, Could you please share the standalone code to reproduce the issue from our end.

Thank you!

lxrswdd commented 1 year ago

@kuaashish Hi, before I go find my codes (it has been some time,I forgot where are they now) I wonder how we usually change the parameters. I don't find the instructions for such an adjustment on the official page. (https://developers.google.com/mediapipe/solutions/vision/face_landmarker/python#image_1).