コード例 #1
0
        /// <summary>
        /// Write bvh data into a file
        /// </summary>
        /// <param name="path"></param>
        public void OutputBVHToFile(string path = "d:/Kinect.bvh")
        {
            // if skeleton struture not clibrated or there is no motion frame, just return
            if (_structuredSkeleton.NeedBoneClibrated() || _frameCount == 0)
            {
                return;
            }

            StringBuilder wholeBVH = new StringBuilder();

            // HIRARCHY
            wholeBVH.Append(STR_HIERARCHY + CHAR_LF);

            // all the joints
            buildBVHOutputSkeleton(_structuredSkeleton.hipRoot);
            wholeBVH.Append(_bvhSkeletonBuffer);

            // MOTION
            wholeBVH.Append(STR_MOTION + CHAR_LF);

            // frame info
            wholeBVH.Append(STR_FRAMES + CHAR_SPACE + _frameCount + CHAR_LF);
            wholeBVH.Append(STR_FRAME_TIME + CHAR_SPACE + DOUBLE_FRAMERATE + CHAR_LF);

            // frames
            wholeBVH.Append(_bvhMotionFrameBuffer);

            // write out
            using (StreamWriter bvhStreamWriter = new StreamWriter(path))
            {
                bvhStreamWriter.Write(wholeBVH.ToString());
            }
        }
コード例 #2
0
        public void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons      = new Skeleton[0];
            long       frameTimeStamp = 0;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                    frameTimeStamp = skeletonFrame.Timestamp;
                }
            }

            if (skeletons.Length != 0)
            {
                canvas.Children.Clear();
                foreach (Skeleton skel in skeletons)
                {
                    // render clipped edges
                    renderClippedEdges(skel);

                    if (SkeletonTrackingState.Tracked == skel.TrackingState)
                    {
                        // clibrate the bones if not done yet
                        _structuredSkeleton.CliberateSkeleton(skel);

                        // render the skeleton on the canvas
                        addBones(skel);

                        if (!_structuredSkeleton.NeedBoneClibrated())
                        {
                            this.grid.Background = Brushes.AntiqueWhite;
                            _structuredSkeleton.UpdateJoints(skel);

                            // record motion data to bvh file
                            if (underRecording)
                            {
                                bvhWriter.AppendOneMotionFrame();
                            }

                            // render bones for debug
                            //addTPose_Debug();

                            DebugData.UpdateSkeletonForDebug(_structuredSkeleton.hipRoot);
                            addBVHBones_Debug();
                        }
                    }
                }
            }
        }