将Python(PyKinect)骨架数据转换为点(X,Y) [英] Converting Python (PyKinect) Skeleton data to Points (X,Y)

查看:617
本文介绍了将Python(PyKinect)骨架数据转换为点(X,Y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的问题,但是我是Python的新手,我似乎无法完成.

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

我想将Python(PyKinect)中的骨架数据坐标转换为点(X,Y).我知道可以在C#(使用Microsoft.Kinect库)中完成类似的任务,如以下代码所示:

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);

            // ...

但是在Python中(使用PyKinect),我能够获取数据对象:

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)

输出为:

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

但是,我似乎无法将其转换为Point(X,Y)格式.我是否需要为此使用NumPy或其他一些外部Python库?任何建议将不胜感激.

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.

推荐答案

您可以使用regex提取值,我不确定这是否是您要查找的内容,但是请尝试以下操作:

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)

输出:

('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])

输出:

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

这篇关于将Python(PyKinect)骨架数据转换为点(X,Y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆