Exemplo n.º 1
2
		private async void StreamSkeleton()
		{
			try
			{
                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
					BinaryReader br = new BinaryReader(ms);

					SkeletonFrameData frame = br.ReadSkeletonFrame();

					SkeletonFrameReadyEventArgs args = new SkeletonFrameReadyEventArgs { SkeletonFrame = frame };
					SkeletonFrame = frame;

					Context.Send(delegate
					{
						if(SkeletonFrameReady != null)
							SkeletonFrameReady(this, args);
					}, null);
				}
			}
			catch(IOException)
			{
                Disconnect();
			}
		}
Exemplo n.º 2
0
        private void StreamSkeleton()
        {
            try
            {
                NetworkStream ns = Client.GetStream();
                BinaryReader reader = new BinaryReader(ns);

                while(Client.Connected)
                {
                    int size = reader.ReadInt32();
                    byte[] data = reader.ReadBytes(size);

                    MemoryStream ms = new MemoryStream(data);
                    BinaryReader br = new BinaryReader(ms);

                    SkeletonFrameData frame = br.ReadSkeletonFrame();

                    SkeletonFrameReadyEventArgs args = new SkeletonFrameReadyEventArgs { SkeletonFrame = frame };
                    SkeletonFrame = frame;

                    Context.Send(delegate
                    {
                        if(SkeletonFrameReady != null)
                            SkeletonFrameReady(this, args);
                    }, null);
                }
            }
            catch(IOException)
            {
                Client.Close();
            }
        }
Exemplo n.º 3
0
		public static SkeletonFrameData ReadSkeletonFrame(this BinaryReader br)
		{
			SkeletonFrameData frame = new SkeletonFrameData();

			frame.FloorClipPlane = new Tuple<float,float,float,float>(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
			frame.FrameNumber = br.ReadInt32();
			frame.SkeletonArrayLength = br.ReadInt32();
			frame.Timestamp = br.ReadInt64();

			frame.Skeletons = new Skeleton[frame.SkeletonArrayLength];
			for(int i = 0; i < frame.Skeletons.Length; i++)
			{
				frame.Skeletons[i] = new Skeleton();
				frame.Skeletons[i].ClippedEdges = (FrameEdges)br.ReadInt32();
				int jointCount = br.ReadInt32();
				frame.Skeletons[i].Joints = new Joint[jointCount];
				for(int jx = 0; jx < jointCount; jx++)
				{
					frame.Skeletons[i].Joints[jx].JointType = (JointType)br.ReadInt32();
					frame.Skeletons[i].Joints[jx].Position = new SkeletonPoint { X = br.ReadSingle(), Y = br.ReadSingle(), Z = br.ReadSingle() };
					frame.Skeletons[i].Joints[jx].TrackingState = (JointTrackingState)br.ReadInt32();
				}
				frame.Skeletons[i].Position = new SkeletonPoint { X = br.ReadSingle(), Y = br.ReadSingle(), Z = br.ReadSingle() };
				frame.Skeletons[i].TrackingId = br.ReadInt32();
				frame.Skeletons[i].TrackingState = (SkeletonTrackingState)br.ReadInt32();
			}

			return frame;
		}
Exemplo n.º 4
0
		void SkeletonClient_FrameReady(object sender, FrameReadyEventArgs e)
		{
			MemoryStream ms = new MemoryStream(e.Data);
			BinaryReader br = new BinaryReader(ms);

			SkeletonFrameData frame = br.ReadSkeletonFrame();
			
			SkeletonFrameReadyEventArgs args = new SkeletonFrameReadyEventArgs { SkeletonFrame = frame };
			SkeletonFrame = frame;

			if(SkeletonFrameReady != null)
				SkeletonFrameReady(this, args);
		}
Exemplo n.º 5
0
        public void UpdateSkeleton(SkeletonFrameData skeletonFrameData, InputSkeletonType inputSkeletonType)
        {
            if (lineRenderer == null)
            {
                Debug.Log("LineRenderer STILL not found!");
            }

            NUIJointType[] currentOrder = new NUIJointType[0];

            if (inputSkeletonType != skeletonType)
            {
                switch (inputSkeletonType)
                {
                case InputSkeletonType.Kinect1_20Joint:
#if UNITY_5_5_OR_NEWER
                    lineRenderer.positionCount = 29;
#else
                    lineRenderer.SetVertexCount(29);
#endif
                    currentOrder = Skeleton20JointOrder;
                    break;

                case InputSkeletonType.Kinect2_25Joint:
#if UNITY_5_5_OR_NEWER
                    lineRenderer.positionCount = 38;
#else
                    lineRenderer.SetVertexCount(38);
#endif
                    currentOrder = Skeleton25JointOrder;
                    break;
                }
            }

            Vector3 pos;
            int     index = 0;

            // don't care about below variables, but they're needed
            Quaternion    q;
            TrackingState ts;

            foreach (NUIJointType njt in currentOrder)
            {
                pos = Vector3.zero;

                skeletonFrameData.GetJointData(njt, out pos, out q, out ts);

                lineRenderer.SetPosition(index, pos);

                index++;
            }
        }
Exemplo n.º 6
0
        public override void Update()
        {
            if (bodyReader != null)
            {
                getMainUser();
            }

            foreach (var viewer in viewers)
            {
                viewer.Update(bodyData, 0);
            }

            // Get the pose.
            if (currentBody != null && currentBody.IsTracked)
            {
                // Encapsulate the important frame data
                SkeletonFrameData frameData = new SkeletonFrameData();
                frameData.TrackingId = currentBody.TrackingId;
                frameData.IsTracked  = currentBody.IsTracked;

                // Build the skeleton
                for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
                {
                    NUIJointType jointType = NUICaptureHelper.JointTypeToNUIJointTypeMapping(jt);

                    Vector3 position = new Vector3(currentBody.Joints[jt].Position.X, currentBody.Joints[jt].Position.Y, currentBody.Joints[jt].Position.Z);
                    position.z *= -1; // Should probably be done with meta data/mapper to avoid disturbing raw data.

                    Quaternion orientation = new Quaternion(currentBody.JointOrientations[jt].Orientation.X, currentBody.JointOrientations[jt].Orientation.Y, currentBody.JointOrientations[jt].Orientation.Z, currentBody.JointOrientations[jt].Orientation.W);

                    frameData.AddJoint(jointType, position, orientation, (CinemaSuite.CinemaMocap.System.Core.TrackingState)currentBody.Joints[jt].TrackingState);
                }

                // Hand info
                frameData.LeftHandConfidence = (CinemaSuite.CinemaMocap.System.Core.TrackingConfidence)currentBody.HandLeftConfidence;
                frameData.LeftHandState      = (CinemaSuite.CinemaMocap.System.Core.HandState)currentBody.HandLeftState;

                frameData.RightHandConfidence = (CinemaSuite.CinemaMocap.System.Core.TrackingConfidence)currentBody.HandRightConfidence;
                frameData.RightHandState      = (CinemaSuite.CinemaMocap.System.Core.HandState)currentBody.HandRightState;

                // Frame info
                frameData.ClippedEdges = (CinemaSuite.CinemaMocap.System.Core.FrameEdges)currentBody.ClippedEdges;

                FrameDataEventArgs args = new FrameDataEventArgs(frameData);
                OnFrameCaptured(args);
            }
        }
        public override void Update()
        {
            if (ZigEditorInput.Instance.ReaderInited)
            {
                // Update Device
                ZigEditorInput.Instance.Update();

                // Get the tracked user
                ZigTrackedUser user   = null;
                int            userId = 0;
                foreach (KeyValuePair <int, ZigTrackedUser> trackedUser in ZigEditorInput.Instance.TrackedUsers)
                {
                    user   = trackedUser.Value;
                    userId = trackedUser.Key;
                }

                // Update viewers
                foreach (Kinect1EditorViewer viewer in viewers)
                {
                    viewer.Update(ZigEditorInput.Instance, userId);
                }

                if (user != null && user.SkeletonTracked)
                {
                    // Encapsulate the important frame data
                    SkeletonFrameData frameData = new SkeletonFrameData();
                    frameData.TrackingId = (ulong)user.Id;
                    frameData.IsTracked  = user.SkeletonTracked;

                    foreach (ZigInputJoint inputJoint in user.Skeleton)
                    {
                        NUIJointType jointType = NUICaptureHelper.ZigToNUIJointMapping(inputJoint.Id);

                        // Convert position from mm to meters
                        Vector3    position    = inputJoint.Position / 1000f;
                        Quaternion orientation = inputJoint.Rotation;

                        frameData.AddJoint(jointType, position, orientation, inputJoint.Inferred ? TrackingState.Inferred : TrackingState.Tracked);
                    }

                    FrameDataEventArgs args = new FrameDataEventArgs(frameData);
                    OnFrameCaptured(args);
                }
            }
        }
Exemplo n.º 8
0
        public static NUISkeleton GetNUISkeleton(SkeletonFrameData skeleton)
        {
            var nuiSkeleton = new NUISkeleton();

            for (NUIJointType jt = NUIJointType.SpineBase; jt <= NUIJointType.ThumbRight; jt++)
            {
                Vector3    position      = new Vector3();
                Quaternion orientation   = new Quaternion();
                var        trackingState = CinemaSuite.CinemaMocap.System.Core.TrackingState.NotTracked;

                skeleton.GetJointData(jt, out position, out orientation, out trackingState);

                NUIJoint joint = new NUIJoint(jt, position, orientation, trackingState != CinemaSuite.CinemaMocap.System.Core.TrackingState.Tracked);
                if (!nuiSkeleton.Joints.ContainsKey(jt))
                {
                    nuiSkeleton.Joints.Add(jt, joint);
                }
            }

            return(nuiSkeleton);
        }
Exemplo n.º 9
0
		void client_SkeletonFrameReady(object sender, SkeletonFrameData e)
		{
			Skeleton skeleton = (from s in e.Skeletons
									 where s.TrackingState == SkeletonTrackingState.Tracked
									 select s).FirstOrDefault();

			if(skeleton == null)
				return;

			SetEllipsePosition(headEllipse, skeleton.Joints[(int)JointType.Head]);
			SetEllipsePosition(leftEllipse, skeleton.Joints[(int)JointType.HandLeft]);
			SetEllipsePosition(rightEllipse, skeleton.Joints[(int)JointType.HandRight]);
		}
Exemplo n.º 10
0
 public FrameDataEventArgs(SkeletonFrameData frameData)
 {
     this.SkeletonFrameData = frameData;
 }