在轮询模型中什么不能获得骨架? [英] what can't obtain skeleton in polling model ?

查看:71
本文介绍了在轮询模型中什么不能获得骨架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


大家好。



using WPF and polling-model。



我有一个问题   获得
hipcenter of skeleton。



我想在我的代码中读取HipCenter1的位置值,但我无法获取数据



数据有trackID,但没有骨架信息    trackID 。 



我不知道该怎么办。



任何建议都很好。



代码:

使用System; 
使用System.Collections.Generic;
使用System。 Linq;
使用System.Text;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows .Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用Microsoft.Kinect;
使用System.IO.Ports;
使用System.Threading;


namespace BeginningKinect.Chapter2.Polling
{
///< summary>
/// MainWindow.xaml的交互逻辑
///< / summary>
public partial class MainWindow:Window
{

///////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// /
private ColorImageStream colorStream;
private KinectSensor _Kinect;

private WriteableBitmap _ColorImageBitmap;
private Int32Rect _ColorImageBitmapRect;
private int _ColorImageStride;
private byte [] _ColorImagePixelData;
private byte [] _ColorImagePixelData1;
private WriteableBitmap _ColorImageBitmap1;
private Int32Rect _ColorImageBitmapRect1;
private int _ColorImageStride1;
//

private Skeleton [] skeletonData;
private Skeleton [] skeletonData1;
//

private int mark;
//

private bool switch_1 = false;
//

私人浮动Hip_X,Hip_G,Hip_NEW_G,Hip_ERROR_G;
private float Hip_Y,Hip_B,Hip_NEW_B,Hip_ERROR_B;
private float Hip_Z,Hip_R,Hip_NEW_R,Hip_ERROR_R;
//私有双总数,标量= 0,标量1 = 0;
// private float x,y,z;
private int nearestID = 0;
int memory_1,memory_2;
int count = 0;
//


#region
//私人WriteableBitmap _DepthImageBitmap;
// private Int32Rect _DepthImageBitmapRect;
// private int _DepthImageStride;
// private short [] _DepthImagePixelData;
//
#endregion
//
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

////////////////////////////////////////// ////////////////////////////////////////////////// //////////////////////////////////////

public MainWindow()
{
InitializeComponent();




CompositionTarget.Rendering + = CompositionTarget_Rendering;
}


private void CompositionTarget_Rendering(object sender,EventArgs e)
{
DiscoverKinectSensor();
PollStream();
textBox3.Text = Convert.ToString(sw.ElapsedTicks);

}
///////////////////////////////////// ////////////////////////////////////////////////// ///////////////////////////////////////////
private void DiscoverKinectSensor ()

{

if(this._Kinect!= null&& this._Kinect.Status!= KinectStatus.Connected)
{
this._Kinect = null;
}

if(this._Kinect == null)
{
this._Kinect = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected);

#region
if(this._Kinect!= null)
{
this._Kinect.ColorStream.Enable();
this._Kinect.SkeletonStream.Enable();
this._Kinect.Start();

colorStream = this._Kinect.ColorStream;
this._ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth,colorStream.FrameHeight,96,96,PixelFormats.Bgr32,null);
this._ColorImageBitmapRect = new Int32Rect(0,0,colorStream.FrameWidth,colorStream.FrameHeight);
this._ColorImageStride = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
this.Color_Image.Source = this._ColorImageBitmap;

this._ColorImageBitmap1 = new WriteableBitmap(colorStream.FrameWidth,colorStream.FrameHeight,96,96,PixelFormats.Bgr32,null);
this._ColorImageBitmapRect1 = new Int32Rect(0,0,colorStream.FrameWidth,colorStream.FrameHeight);
this._ColorImageStride1 = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
}
#endregion
//

#region
// if(this._Kinect!= null)
// {
// this._Kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
// this._Kinect.Start();
//
// DepthImageStream depthStream = this._Kinect.DepthStream;
// this._DepthImageBitmap = new WriteableBitmap(depthStream.FrameWidth,depthStream.FrameHeight,96,96,PixelFormats.Gray16,null);
// this._DepthImageBitmapRect = new Int32Rect(0,0,depthStream.FrameWidth,depthStream.FrameHeight);
// this._DepthImageStride = depthStream.FrameWidth * depthStream.FrameBytesPerPixel;
// this.DepthImageElement.Source = this._DepthImageBitmap;
// this._DepthImagePixelData = new short [depthStream.FramePixelDataLength];
//}

// if(this._Kinect!= null)
// {
// this._Kinect.SkeletonStream.Enable();
// this._Kinect.Start();
//}
#endregion
//
}
}


private void PollStream()
{
if(this._Kinect == null)
{
// TODO:显示插入Kinect的消息。
}
其他
{


#region
使用(ColorImageFrame frame = this._Kinect.ColorStream.OpenNextFrame(100))
{

if(frame!= null)
{
this._ColorImagePixelData = new byte [colorStream.FramePixelDataLength];
frame.CopyPixelDataTo(this._ColorImagePixelData);

this._ColorImageBitmap.WritePixels(this._ColorImageBitmapRect,this._ColorImagePixelData,this._ColorImageStride,0);
//
}
}
#endregion



#region
//使用(DepthImageFrame帧) = this._Kinect.DepthStream.OpenNextFrame(100))
// {
// if(frame!= null)
// {
// frame.CopyPixelDataTo(this ._DepthImagePixelData);
//
// this._DepthImageBitmap.WritePixels(this._DepthImageBitmapRect,this._DepthImagePixelData,this._DepthImageStride,0);
// //
//}
//}
#endregion



使用(SkeletonFrame frame = this ._Kinect.SkeletonStream.OpenNextFrame(100))
{

if(frame!= null)
{
skeletonData = new Skeleton [_Kinect.SkeletonStream.FrameSkeletonArrayLength] ;
frame.CopySkeletonDataTo(this.skeletonData);


if(this._Kinect!= null&& this._Kinect.SkeletonStream!= null)
{
if(!this._Kinect.SkeletonStream) .AppChoosesSkeletons)
{
this._Kinect.SkeletonStream.AppChoosesSkeletons = true;
}

float nearestDistance = 10000f;
count = 0;

foreach(this.skeletonData.Where中的骷髅骨架(s => s.TrackingState!= SkeletonTrackingState.NotTracked))
{
count = count + 1;
if(count == 1)
{
memory_1 = skeleton.TrackingId;
}
if(count == 2)
{
memory_2 = skeleton.TrackingId;
}
}

foreach(this.skeletonData.Where中的Skeleton skeleton1(s => s.TrackingState!= SkeletonTrackingState.NotTracked))
{
if(skeleton1.Position.Z< nearestDistance&& switch_1 == false)
{
nearestID = skeleton1.TrackingId;
nearestDistance = skeleton1.Position.Z;
}
}

if(memory_1!= nearestID&& switch_1 == true)
{

using(ColorImageFrame frame1 = this._Kinect.ColorStream.OpenNextFrame(100))
{
if(frame1!= null)
{
colorStream = this._Kinect.ColorStream;

this._ColorImagePixelData1 = new byte [colorStream.FramePixelDataLength];
frame1.CopyPixelDataTo(_ColorImagePixelData1);

this._ColorImageBitmap1.WritePixels(this._ColorImageBitmapRect1,this._ColorImagePixelData1,this._ColorImageStride1,0);
this.Color_Image2.Source = this._ColorImageBitmap1;

}
}

使用(SkeletonFrame frame2 = this._Kinect.SkeletonStream.OpenNextFrame(1000))
{
if(frame2 != null)
{


skeletonData1 = new Skeleton [_Kinect.SkeletonStream.FrameSkeletonArrayLength];
frame2.CopySkeletonDataTo(this.skeletonData1);

foreach(this.skeletonData1.Where中的Skeleton skeleton4(s => s.TrackingState!= SkeletonTrackingState.NotTracked))
{

var HipCenter1 = skeleton4 .Joints [JointType.HipCenter] .POSITION;


ColorImagePoint colorImagePoint1 = _Kinect.CoordinateMapper.MapSkeletonPointToColorPoint(HipCenter1,ColorImageFormat.RgbResolution640x480Fps30);
//
textBox1.Text = Convert.ToString(colorImagePoint1.X)+"," + Convert.ToString(colorImagePoint1.Y)+"," + Convert.ToString(skeleton4.TrackingId);
//
if(colorImagePoint1.X< = 608&& 0< = colorImagePoint1.X&& 0< = colorImagePoint1.Y&& colorImagePoint1.Y< = 306)
{
Hip_NEW_B = _ColorImagePixelData1 [colorImagePoint1.X * 4 +((colorImagePoint1.Y - 1)* 640 * 4)];
Hip_NEW_G = _ColorImagePixelData1 [colorImagePoint1.X * 4 +((colorImagePoint1.Y - 1)* 640 * 4)+ 1];
Hip_NEW_R = _ColorImagePixelData1 [colorImagePoint1.X * 4 +((colorImagePoint1.Y - 1)* 640 * 4)+ 2];

}

Hip_ERROR_G = Math.Abs​​(Hip_NEW_G - Hip_G);
Hip_ERROR_B = Math.Abs​​(Hip_NEW_B - Hip_B);
Hip_ERROR_R = Math.Abs​​(Hip_NEW_R - Hip_R);


if(Hip_ERROR_G< = 30&& Hip_ERROR_B< = 30&& Hip_ERROR_R< = 30)
{
nearestID = skeleton4 。跟踪号码;
this._Kinect.SkeletonStream.ChooseSkeletons(nearestID);
//textBox1.Text =" sucessful" ;;
}
}

}
}





}

if(switch_1 == false&& count == 1)
{
sw.Start();
}
if(nearestID!= 0)
{
switch_1 = true;
}


if(nearestID> 0)
{
this._Kinect.SkeletonStream.ChooseSkeletons(nearestID); //跟踪这个骨架
}


Skeleton skeleton3 =(来自skeletonData
中的s,其中s.TrackingState == SkeletonTrackingState.Tracked
select s) .FirstOrDefault();

if(skeleton3!= null)
{

var HipCenter = skeleton3.Joints [JointType.HipCenter];
// var HipRight = skeleton3.Joints [JointType.HipRight];
// var HipLeft = skeleton3.Joints [JointType.HipLeft];
// var handright = skeleton3.Joints [JointType.HandRight];
// var handleft = skeleton3.Joints [JointType.HandLeft];


SetPointPosition(hipPoint,HipCenter);
// SetPointPosition(hiprightPoint,HipRight);
// SetPointPosition(hipleftPoint,HipLeft);
// SetPointPosition(handrightPoint,handright);
// SetPointPosition(handleftPoint,handleft);

Hip_X = HipCenter.Position.X;
Hip_Y = HipCenter.Position.Y;
Hip_Z = HipCenter.Position.Z;

textBox2.Text = Hip_R +"," + Hip_G +"," + Hip_B;
textBox4.Text = Hip_ERROR_B +"," + Hip_ERROR_G +"," + Hip_ERROR_R;
}
}



}
}















}
}

private void SetPointPosition(FrameworkElement ellipse,Joint joint)
{

ColorImagePoint colorImagePoint = _Kinect.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position,ColorImageFormat.RgbResolution640x480Fps30) ;
Canvas.SetLeft(ellipse,colorImagePoint.X);
Canvas.SetTop(ellipse,colorImagePoint.Y);

if(colorImagePoint.X< = 608&& 0< = colorImagePoint.X&< 0< = colorImagePoint.Y&& colorImagePoint.Y< = 306 && sw.ElapsedTicks> = 5000000)
{
Hip_B = _ColorImagePixelData [colorImagePoint.X * 4 +((colorImagePoint.Y - 1)* 640 * 4)];
Hip_G = _ColorImagePixelData [colorImagePoint.X * 4 +((colorImagePoint.Y - 1)* 640 * 4)+ 1];
Hip_R = _ColorImagePixelData [colorImagePoint.X * 4 +((colorImagePoint.Y - 1)* 640 * 4)+ 2];
sw.Stop();
sw.Reset();

}

}





解决方案

由于有超过3个不同的区域,因此很难理解您的代码你正试图抓住骨架信息。我不确定你是否知道,但WPF不适用于这种类型的轮询,应该避免。您可能想要研究
这样做的问题。


至于获取联合信息,您应该只有一个 CopySkeletonDataTo <跨度> skeletonData <跨度>);
这将确保您使用一份数据。这应该只对每1/30秒有效,所以保持它。至于获取骨架联合信息,请遵循样本和文档提供的模式。


http://msdn.microsoft .com / zh-CN / library / jj131025.aspx #Active_User_Tracking


您需要确保正确跟踪要跟踪的正文并且信息有效。


Hi, guys.

using WPF and polling-model.

I have a problem which to obtain hipcenter of skeleton.

I want to read position values of HipCenter1 in my code, but i can't get the data.

The data have trackID, but have not the skeleton information of  trackID

I don't know how to do.

Any suggestions are good.

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.IO.Ports;
using System.Threading;


namespace BeginningKinect.Chapter2.Polling
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private ColorImageStream colorStream;
        private KinectSensor _Kinect;

        private WriteableBitmap _ColorImageBitmap;
        private Int32Rect _ColorImageBitmapRect;
        private int _ColorImageStride;
        private byte[] _ColorImagePixelData;
        private byte[] _ColorImagePixelData1;
        private WriteableBitmap _ColorImageBitmap1;
        private Int32Rect _ColorImageBitmapRect1;
        private int _ColorImageStride1;
        //     

        private Skeleton[] skeletonData;
        private Skeleton[] skeletonData1;
        //

        private int mark;
        //

        private bool switch_1 = false;
        //

        private float Hip_X, Hip_G,Hip_NEW_G,Hip_ERROR_G;
        private float Hip_Y, Hip_B, Hip_NEW_B, Hip_ERROR_B;
        private float Hip_Z, Hip_R, Hip_NEW_R, Hip_ERROR_R;
        //private double total, scalar = 0,scalar1 = 0;
        //private float x, y, z;
        private int closestID = 0;
        int memory_1, memory_2;
        int count = 0;
        //


        #region 
        //private WriteableBitmap _DepthImageBitmap;
        //private Int32Rect _DepthImageBitmapRect;
        //private int _DepthImageStride;
        //private short[] _DepthImagePixelData;
        //
        #endregion
        //
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public MainWindow()
        {
            InitializeComponent();


            
            
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }


        private void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            DiscoverKinectSensor();
            PollStream();
            textBox3.Text = Convert.ToString(sw.ElapsedTicks);
            
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void DiscoverKinectSensor()

        {

            if (this._Kinect != null && this._Kinect.Status != KinectStatus.Connected)
            {
                this._Kinect = null;
            }

            if (this._Kinect == null)
            {
                this._Kinect = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected);
                
                #region
                if (this._Kinect != null)
                {
                    this._Kinect.ColorStream.Enable();
                    this._Kinect.SkeletonStream.Enable();
                    this._Kinect.Start();

                    colorStream = this._Kinect.ColorStream;
                    this._ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null);
                    this._ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                    this._ColorImageStride = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                    this.Color_Image.Source = this._ColorImageBitmap;

                    this._ColorImageBitmap1 = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null);
                    this._ColorImageBitmapRect1 = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                    this._ColorImageStride1 = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                }
                #endregion
                //
                
                #region 
                //if (this._Kinect != null)
                //{
                //    this._Kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                //    this._Kinect.Start();                
                //
                //    DepthImageStream depthStream    = this._Kinect.DepthStream;
                //    this._DepthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Gray16, null);
                //    this._DepthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight);
                //    this._DepthImageStride = depthStream.FrameWidth * depthStream.FrameBytesPerPixel;
                //    this.DepthImageElement.Source = this._DepthImageBitmap;
                //    this._DepthImagePixelData = new short[depthStream.FramePixelDataLength];                                
                //}

                //if (this._Kinect != null)
                //{
                //    this._Kinect.SkeletonStream.Enable();
                //    this._Kinect.Start();  
                //}
                #endregion
                //
            }
        }


        private void PollStream()
        {
            if (this._Kinect == null)
            {
                //TODO: Display a message to plug-in a Kinect.
            }
            else
            {

                
                #region
                using (ColorImageFrame frame = this._Kinect.ColorStream.OpenNextFrame(100))
                {

                    if (frame != null)
                    {
                        this._ColorImagePixelData = new byte[colorStream.FramePixelDataLength];
                        frame.CopyPixelDataTo(this._ColorImagePixelData);
                        
                        this._ColorImageBitmap.WritePixels(this._ColorImageBitmapRect, this._ColorImagePixelData, this._ColorImageStride, 0);
                        //
                    }
                }
                #endregion


                
                #region
                //using(DepthImageFrame frame = this._Kinect.DepthStream.OpenNextFrame(100))
                //{
                //    if(frame != null)
                //    {                            
                //        frame.CopyPixelDataTo(this._DepthImagePixelData);
                //        
                //        this._DepthImageBitmap.WritePixels(this._DepthImageBitmapRect, this._DepthImagePixelData, this._DepthImageStride, 0);      
                //        //
                //    }
                //}
                #endregion



                using (SkeletonFrame frame = this._Kinect.SkeletonStream.OpenNextFrame(100))
                {

                    if (frame != null)
                    {
                        skeletonData = new Skeleton[_Kinect.SkeletonStream.FrameSkeletonArrayLength];
                        frame.CopySkeletonDataTo(this.skeletonData);


                        if (this._Kinect != null && this._Kinect.SkeletonStream != null)
                        {
                            if (!this._Kinect.SkeletonStream.AppChoosesSkeletons)
                            {
                                this._Kinect.SkeletonStream.AppChoosesSkeletons = true;
                            }

                            float closestDistance = 10000f;
                            count = 0;

                            foreach (Skeleton skeleton in this.skeletonData.Where(s => s.TrackingState != SkeletonTrackingState.NotTracked))
                            {
                                count = count + 1;
                                if (count == 1)
                                {
                                    memory_1 = skeleton.TrackingId;
                                }
                                if (count == 2)
                                {
                                    memory_2 = skeleton.TrackingId;
                                }
                            }

                            foreach (Skeleton skeleton1 in this.skeletonData.Where(s => s.TrackingState != SkeletonTrackingState.NotTracked))
                            {
                                if (skeleton1.Position.Z < closestDistance && switch_1 == false)
                                {
                                    closestID = skeleton1.TrackingId;
                                    closestDistance = skeleton1.Position.Z;
                                }
                            }

                            if (memory_1 != closestID && switch_1 == true)
                            {

                                using (ColorImageFrame frame1 = this._Kinect.ColorStream.OpenNextFrame(100))
                                {
                                    if (frame1 != null)
                                    {
                                        colorStream = this._Kinect.ColorStream;

                                        this._ColorImagePixelData1 = new byte[colorStream.FramePixelDataLength];
                                        frame1.CopyPixelDataTo(_ColorImagePixelData1);

                                        this._ColorImageBitmap1.WritePixels(this._ColorImageBitmapRect1, this._ColorImagePixelData1, this._ColorImageStride1, 0);
                                        this.Color_Image2.Source = this._ColorImageBitmap1;

                                    }
                                }

                                using (SkeletonFrame frame2 = this._Kinect.SkeletonStream.OpenNextFrame(1000))
                                {
                                    if (frame2 != null)
                                    {

                                        
                                        skeletonData1 = new Skeleton[_Kinect.SkeletonStream.FrameSkeletonArrayLength];
                                        frame2.CopySkeletonDataTo(this.skeletonData1);

                                        foreach (Skeleton skeleton4 in this.skeletonData1.Where(s => s.TrackingState != SkeletonTrackingState.NotTracked))
                                        {

                                            var HipCenter1 = skeleton4.Joints[JointType.HipCenter].Position;


                                            ColorImagePoint colorImagePoint1 = _Kinect.CoordinateMapper.MapSkeletonPointToColorPoint(HipCenter1, ColorImageFormat.RgbResolution640x480Fps30);
                                            //
                                            textBox1.Text = Convert.ToString(colorImagePoint1.X) + "," + Convert.ToString(colorImagePoint1.Y) + "," +  Convert.ToString(skeleton4.TrackingId);
                                            //
                                            if (colorImagePoint1.X <= 608 && 0 <= colorImagePoint1.X && 0 <= colorImagePoint1.Y && colorImagePoint1.Y <= 306)
                                            {
                                                Hip_NEW_B = _ColorImagePixelData1[colorImagePoint1.X * 4 + ((colorImagePoint1.Y - 1) * 640 * 4)];
                                                Hip_NEW_G = _ColorImagePixelData1[colorImagePoint1.X * 4 + ((colorImagePoint1.Y - 1) * 640 * 4) + 1];
                                                Hip_NEW_R = _ColorImagePixelData1[colorImagePoint1.X * 4 + ((colorImagePoint1.Y - 1) * 640 * 4) + 2];

                                            }

                                            Hip_ERROR_G = Math.Abs(Hip_NEW_G - Hip_G);
                                            Hip_ERROR_B = Math.Abs(Hip_NEW_B - Hip_B);
                                            Hip_ERROR_R = Math.Abs(Hip_NEW_R - Hip_R);


                                            if (Hip_ERROR_G <= 30 && Hip_ERROR_B <= 30 && Hip_ERROR_R <= 30)
                                            {
                                                closestID = skeleton4.TrackingId;
                                                this._Kinect.SkeletonStream.ChooseSkeletons(closestID);
                                                //textBox1.Text = "sucessful";
                                            }
                                        }

                                    }
                                }





                            }

                            if (switch_1 == false && count == 1)
                            {
                                sw.Start();
                            }
                            if (closestID != 0)
                            {
                                switch_1 = true;
                            }


                            if (closestID > 0)
                            {
                                this._Kinect.SkeletonStream.ChooseSkeletons(closestID); // Track this skeleton
                            }


                            Skeleton skeleton3 = (from s in skeletonData
                                                  where s.TrackingState == SkeletonTrackingState.Tracked
                                                  select s).FirstOrDefault();

                            if (skeleton3 != null)
                            {

                                var HipCenter = skeleton3.Joints[JointType.HipCenter];
                                //var HipRight = skeleton3.Joints[JointType.HipRight];
                                //var HipLeft = skeleton3.Joints[JointType.HipLeft];
                                //var handright = skeleton3.Joints[JointType.HandRight];
                                //var handleft = skeleton3.Joints[JointType.HandLeft];


                                SetPointPosition(hipPoint, HipCenter);
                                //SetPointPosition(hiprightPoint, HipRight);
                                //SetPointPosition(hipleftPoint, HipLeft);
                                //SetPointPosition(handrightPoint, handright);
                                //SetPointPosition(handleftPoint, handleft);

                                Hip_X = HipCenter.Position.X;
                                Hip_Y = HipCenter.Position.Y;
                                Hip_Z = HipCenter.Position.Z;

                                textBox2.Text = Hip_R + "," + Hip_G + "," + Hip_B;
                                textBox4.Text = Hip_ERROR_B + "," + Hip_ERROR_G + "," + Hip_ERROR_R;
                            }
                        }



                    }
                }















            }
        }

        private void SetPointPosition(FrameworkElement ellipse, Joint joint)
        {

            ColorImagePoint colorImagePoint = _Kinect.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
            Canvas.SetLeft(ellipse, colorImagePoint.X);
            Canvas.SetTop(ellipse, colorImagePoint.Y);

            if (colorImagePoint.X <= 608 && 0 <= colorImagePoint.X && 0 <= colorImagePoint.Y && colorImagePoint.Y <= 306 && sw.ElapsedTicks>= 5000000)
            {
            Hip_B = _ColorImagePixelData[colorImagePoint.X * 4 + ((colorImagePoint.Y - 1) * 640 * 4)];
            Hip_G = _ColorImagePixelData[colorImagePoint.X * 4 + ((colorImagePoint.Y - 1) * 640 * 4) + 1];
            Hip_R = _ColorImagePixelData[colorImagePoint.X * 4 + ((colorImagePoint.Y - 1) * 640 * 4) + 2];
            sw.Stop();   
            sw.Reset();

            }
            
        }


解决方案

It is very difficult to understand your code as there are over 3 different areas where you are trying to grab skeleton information. I am not sure if you are aware, but WPF is not designed for this type of polling and should be avoided. You may want to research the issues with doing that.

As for getting joint information, you should only have one CopySkeletonDataTo(this.skeletonData); This will ensure you are working with one copy of the data. This should only be valid for every 1/30 of a second so keep it around. As for getting skeleton joint information follow the pattern provided by the samples and docs.

http://msdn.microsoft.com/en-us/library/jj131025.aspx#Active_User_Tracking

You need to ensure you are correctly tracking the body you wish to track and the information is valid.


这篇关于在轮询模型中什么不能获得骨架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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