简体   繁体   中英

Extract the gesture from GestureRecognizerResult

In the mediapipe library, there is a task called GestureRecognizer which can recognize certain hand gestures. There is also a task called GestureRecognizerResult which consists of the results from the GestureRecognizer . GestureRecognizerResult has an attribute called gesture , which when printed shows the following output

> print(getattr(GestureRecognizerResult, 'gestures'))
#[[Category(index=-1, score=0.8142859935760498, display_name='', category_name='Open_Palm')]]

I actually want just the category_name to be printed, how can I do that?

Thanks in advance.

According to the API documentation , GestureRecognizerResult has the following attributes:

mp.tasks.vision.GestureRecognizerResult(
    gestures: List[List[category_module.Category]],
    handedness: List[List[category_module.Category]],
    hand_landmarks: List[List[landmark_module.NormalizedLandmark]],
    hand_world_landmarks: List[List[landmark_module.Landmark]]
)

The gestures attribute is a List of gestures, each with a List of categories, so you can access those categories using the following:

for gesture in recognition_result.gestures:
    print([category.category_name for category in gesture])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM