ibaiGorordo / pyKinectAzure

Python library to run Kinect Azure DK SDK functions
MIT License
459 stars 113 forks source link

Put K4ABT_JOINT_ constants into enum and use them consistently #109

Open StephanHasler opened 1 year ago

StephanHasler commented 1 year ago

I like to send detected skeletons from one program to another in a custom format. In this format I like to refer to each body joint by its name like SHOULDER_LEFT rather than its ID 5. I could map IDs to names using the K4ABT_JOINT_NAMES list. But the names in K4ABT_JOINT_NAMES are not really suited for my purpose, because they contain spaces and dashes and the order of words is reversed.

I would prefer to get the name directly from the constant. This would be much easier if the constants are part of an enum.

from enum import Enum

class K4ABT_JOINTS(Enum):
    K4ABT_JOINT_PELVIS = 0
    K4ABT_JOINT_SPINE_NAVEL = 1
    K4ABT_JOINT_SPINE_CHEST = 2
    K4ABT_JOINT_NECK = 3

# Now its easy to get the name of the joint from the ID
K4ABT_JOINTS(0).name 
'K4ABT_JOINT_PELVIS'

K4ABT_JOINTS(3).name 
'K4ABT_JOINT_NECK'

If you have no objections against this, I could provide a pull request.

Also the JOINT constants could be used more consistently. Currently, in the definition of the K4ABT_SEGMENT_PAIRS the indices are used instead of the constants.