I'm working on a project using MediaPipe to detect hand landmarks. While the detection is working fine, I want to customize the visualization. Instead of the default connections and dots provided by mp_drawing.draw_landmarks(), I want to overlay custom shapes (like circles, squares, or even images) on specific landmarks.
Here’s what I’ve tried so far:
- I used
mp_drawing.draw_landmarks()to visualize the landmarks. - I modified the
mp_drawing.DrawingSpecto change colors and thicknesses, but that still uses the default rendering.
Here’s a minimal code snippet of what I currently have:
import cv2
import mediapipe as mp
mp_hands = mp.solutions.hands
mp_drawing = mp.solutions.drawing_utils
cap = cv2.VideoCapture(0)
with mp_hands.Hands() as hands:
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(frame)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
cv2.imshow("MediaPipe Hands", frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
My Goal:
- Instead of just drawing dots, I want to add custom shapes (e.g., larger circles, squares, or images like a star icon) to specific landmarks like the wrist or fingertips.
Questions:
- How can I overlay custom shapes or images on specific landmarks detected by MediaPipe?
- Can I completely skip
mp_drawing.draw_landmarks()and manually draw all landmarks and connections? If yes, what’s the best way to do this?
Any help or guidance would be appreciated!