这是一个非常简单的问题,但我是Python的新手,我似乎无法实现它。
我想将Python(PyKinect)中的Skeleton数据坐标转换为Points(X,Y)。 我知道类似的任务可以在C#(使用Microsoft.Kinect库)中实现,如下面的代码:
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),我能够获取数据对象:
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库吗? 任何建议真的很感激。
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.
最满意答案
你可以使用regex来提取值,我不确定这是你正在寻找的但是试试这个:
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'))或者如果你想要一个更清洁的版本:
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')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')更多推荐
发布评论