Converting Python (PyKinect) Skeleton data to Points (X,Y)

会有一股神秘感。 提交于 2019-12-08 05:34:07

问题


This is a pretty simple issue but I am new to Python and I can't seem to accomplish it.

I want to convert Skeleton data co-ordinates in Python (PyKinect) to Points (X,Y). I know that the similar task can be achieved in C# (using Microsoft.Kinect libraries) like the below code:

var p = new Point[6];
Point shoulderRight = new Point(), shoulderLeft = new Point();

foreach (Joint j in data.Joints)
{
    switch (j.ID)
    {
        case JointID.HandLeft:
            p[0] = new Point(j.Position.X, j.Position.Y);

            // ...

In Python (using PyKinect) though, I am able to get the data object:

for index, data in enumerate(skeletons):
p2 = data.SkeletonPositions[JointId.wrist_left] #test left wrist joint data object
print ('p2', p2)

The output is:

('p2', <x=-0.5478253364562988, y=-0.5376561880111694, z=1.7154035568237305, w=1.0>)

But, I can't seem to convert it into Point(X,Y) format. Will I need to use NumPy or some other external Python library for this? Any suggestions would really be appreciated.


回答1:


You can use regex to extract the values, I am not sure if this is what you are looking for but try this:

import re

p2 = "<x=-0.5478253364562988, y=-0.5376561880111694, z=1.7154035568237305, w=1.0>"
p2 = re.findall("-?\d+.\d+",p2)
p2_xy = p2[0],p2[1]
print ("p2",p2_xy)

Output:

('ps', ('-0.5478253364562988', '-0.5376561880111694'))

Or if you want a more cleaner version:

import re

p2 = "<x=-0.5478253364562988, y=-0.5376561880111694, z=1.7154035568237305, w=1.0>"
p2 = re.findall("-?\d+.\d+",p2)
print ("p2",p2[0],p2[1])

Output:

('p2', '-0.5478253364562988', '-0.5376561880111694')


来源:https://stackoverflow.com/questions/14144644/converting-python-pykinect-skeleton-data-to-points-x-y

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!