The given code takes in a list of handedness objects and returns a list of the labels of the hands present in the frame.

For example, if a single hand is present in the frame, the function returns a list with one element, which is the label of the hand.

If two hands are present in the frame, the function returns a list with two elements, which are the labels of the left and right hands, in that order.

However, this code assumes that the handedness objects are sorted in a specific order, which may not always be the case.

Therefore, it is better to first check which hand is which, and then return the labels accordingly.

def checkHandsIndex(handedness): # Check the number of hands in the frame num_hands = len(handedness)

# Create a dictionary to store the handedness objects
handedness_dict = {}

# Iterate over the handedness objects and store them in the dictionary based on the hand type
for hand in handedness:
    hand_label = hand.classification[0].label
    if hand_label == "Left":
        handedness_dict["left"] = hand
    elif hand_label == "Right":
        handedness_dict["right"] = hand

# Check which hand is present in the frame and return the labels accordingly
if num_hands == 1:
    hand_label = handedness_dict["left"].classification[0].label if "left" in handedness_dict else handedness_dict["right"].classification[0].label
    return [hand_label]
elif num_hands == 2:
    left_label = handedness_dict["left"].classification[0].label if "left" in handedness_dict else ""
    right_label = handedness_dict["right"].classification[0].label if "right" in handedness_dict else ""
    return [left_label, right_label]
else:
    return [
def checkHandsIndexself handedness # 判断手的数量 if lenhandedness == 1 handedness_list = handedness0classification0label else handedness_list = handedness0classif

原文地址: https://www.cveoy.top/t/topic/eDhw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录