79483978

Date: 2025-03-04 14:33:45
Score: 1
Natty:
Report link

You're using the built-in Mediapipe function draw_landmarks to handle all the drawings. This function takes an image, a normalized landmark list, and connections as inputs. However, the NormalizedLandmarkList type in Mediapipe doesn’t support merging multiple landmark lists, making it difficult to pass landmarks for both hands to the function and find connections.

An alternative approach is to extract the coordinates from the hand landmarks and draw a line using the cv2.line method, as you mentioned. Here’s the code to implement this approach:

    right_hand_landmarks = results.right_hand_landmarks
    left_hand_landmarks = results.left_hand_landmarks
    
    # try to render a line if both hands are detected
    if right_hand_landmarks and left_hand_landmarks:
    
        # find the position of wrist landmark (as it is normalized, it should multiplied by width and height for x and y respectively)
        right_wrist = np.array([right_hand_landmarks.landmark[0].x * image.shape[1], right_hand_landmarks.landmark[0].y * image.shape[0]]).astype("int")
        left_wrist = np.array([left_hand_landmarks.landmark[0].x * image.shape[1], left_hand_landmarks.landmark[0].y * image.shape[0]]).astype("int")
        
        # draw a line between two wrists
        cv2.line(image, right_wrist, left_wrist, color=(255,255,255), thickness=3)
    
    

If you want to select another landmark other than the wrist, check this link to see landmark indices.

Reasons:
  • Blacklisted phrase (1): this link
  • RegEx Blacklisted phrase (1): check this link
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Milad Yousefi