Home > database >  TypeError: draw_landmarks() missing 1 required positional argument: 'landmark_list'
TypeError: draw_landmarks() missing 1 required positional argument: 'landmark_list'

Time:07-07

This is my code that got error it's just exactly same as the tutor.

import cv2
import mediapipe as mp

frameWidth = 1500
frameHeight = 1000
cap = cv2.VideoCapture(0)
cap.set(3, frameWidth)
cap.set(4, frameHeight)
cap.set(10,150)


mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils

while True:
    sucess, img = cap.read()
    imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    results = hands.process(imgRGB)
    # print(results.multi_hand_landmarks)

    if results.multi_hand_landmarks:
        for handLms in results.multi_hand_landmarks:
            mpDraw.draw_landmarks((img, handLms))

    cv2.imshow('img', img)

    if cv2.waitKey(1) & 0xFF ==ord('a'):
        break

cap.release()
cv2.destroyAllWindows()

Error

mpDraw.draw_landmarks((img, handLms, mpHands.HAND_CONNECTIONS))
TypeError: draw_landmarks() missing 1 required positional argument: 'landmark_list'

The tutor is not getting the error I got. The video I watch is https://youtu.be/NZde8Xt78Iw?t=832

Pls let me know if you know the problem. Thank you!

CodePudding user response:

mpDraw.draw_landmarks also requires hand connection information and style, please refer argument info below:

  • image: A three channel BGR image represented as numpy ndarray.
  • landmark_list: A normalized landmark list proto message to be annotated on the image.
  • landmark_drawing_spec: Either a DrawingSpec object or a mapping from hand landmarks to the DrawingSpecs that specifies the landmarks' drawing settings such as color, line thickness, and circle radius. If this argument is explicitly set to None, no landmarks will be drawn.
  • connection_drawing_spec: Either a DrawingSpec object or a mapping from hand connections to the DrawingSpecs that specifies the connections' drawing settings such as color and line thickness. If this argument is explicitly set to None, no landmark connections will be drawn.

Moreover, if this doesn't solve your issue please refer official mediapipe documentation here for hand landmarks detection.

CodePudding user response:

The error lies in this line mpDraw.draw_landmarks((img, handLms))

The function draw_landmarks() expects 2 input arguments: (a) the image (b) list of landmark points on the detected hand. Both these these arguments are separate entities.

However, in your code, you have enclosed both these arguments as a single entity (tuple). Hence the error message asks for the second missing argument.

You need to correct that line by removing the extra parenthesis: mpDraw.draw_landmarks(img, handLms)

  • Related