读取kinect骨架时遇到麻烦
本文关键字:遇到 麻烦 kinect 读取 | 更新日期: 2023-09-27 18:08:37
我是kinect编程的新手,我正在尝试映射一个骨架,它不能正常工作,我正在使用1.6版本的kinect sdk和我的代码运行,但当它到达这部分时它停止了:
void kinectsensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
SkeletonFrame skeletonSet = e.OpenSkeletonFrame();
// Skeleton skeletonData = new Skeleton[kinectsensor.SkeletonStream.FrameSkeletonArrayLength];
**Skeleton skeletonData = (from s in skeletons
where s.TrackingState == SkeletonTrackingState.Tracked
select s).FirstOrDefault();**
if (skeletonData != null)
{
SetEllipsePosition(Head, skeletonData.Joints[JointType.Head]);
SetEllipsePosition(leftHand, skeletonData.Joints[JointType.HandLeft]);
SetEllipsePosition(rightHand, skeletonData.Joints[JointType.HandRight]);
ProcessGesture(skeletonData.Joints[JointType.Head], skeletonData.Joints[JointType.HandLeft], skeletonData.Joints[JointType.HandRight]);
}
}
我得到的警告信息是:
KinectSkeletonApplication3.MainWindow。骷髅从来没有分配过和将始终具有其默认值null
我不太了解Kinect编程,但你需要从某些东西中分配骨架数组,也许使用copySkeletonDataTo()
典型的SkeletonFrameReady
回调是这样的:
private Skeleton[] skeletonData;
private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
int skeletonSlot = 0;
if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
{
this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
}
skeletonFrame.CopySkeletonDataTo(this.skeletonData);
foreach (Skeleton skeleton in this.skeletonData)
{
if (SkeletonTrackingState.Tracked == skeleton.TrackingState)
{
// `skeleton` is an actively tracked skeleton
}
}
}
}
}
你可以在Kinect for Windows Developer Toolkit和Kinect for Windows CodePlex网站中找到很多这样的例子。