将Python(PyKinect)Skeleton数据转换为Points(X,Y)(Converting Python (PyKinect) Skeleton data to Points (X,Y)

编程入门 行业动态 更新时间:2024-10-27 03:26:20
将Python(PyKinect)Skeleton数据转换为Points(X,Y)(Converting Python (PyKinect) Skeleton data to Points (X,Y))

这是一个非常简单的问题,但我是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')

更多推荐

本文发布于:2023-08-03 05:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1383901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   数据   Skeleton   Python   PyKinect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!