示例#1
0
        private AnimationKey KinectFrameToKeyFrame(KinectFrame frame)
        {
            var f = new AnimationKey();

            var mat = Matrix.Identity;
            var prev = Matrix.Identity;

            foreach (var j in frame.Joints.Where(j => LinkedJoints[j.Key].IsValid))
            {
                LinkedJoints[j.Key].LocalMatrix = j.Value.HierarchicalRotation;
            }

            foreach (var joint in LinkedJoints.Values)
            {
                if (!joint.IsValid)
                {
                    f.BoneTransforms.Add(prev);
                    break;
                }

                mat = joint.LocalMatrix;

                f.BoneTransforms.Add(mat);
                prev = mat;
            }
            return f;
        }
        private void RenderFrame(MultiSourceFrame kinectFrame)
        {
            calculateFPS();

            if (!pipeline.Timer.IsRunning)
            {
                return;
            }

            using (var depthFrame = kinectFrame.DepthFrameReference.AcquireFrame())
                using (var colorFrame = kinectFrame.ColorFrameReference.AcquireFrame())
                    using (var irFrame = kinectFrame.InfraredFrameReference.AcquireFrame())
                    {
                        var frame = new KinectFrame();

                        frame.Id           = Guid.NewGuid();
                        frame.RelativeTime = pipeline.Timer.ElapsedTime;

                        depthFrame.CopyFrameDataToIntPtr(frame.InfraredPixels, (uint)Kinect2Metrics.DepthBufferLength);
                        colorFrame.CopyConvertedFrameDataToIntPtr(frame.ColorPixels, (uint)Kinect2Metrics.ColorBufferLength, ColorImageFormat.Bgra);
                        irFrame.CopyFrameDataToIntPtr(frame.InfraredPixels, (uint)Kinect2Metrics.IRBufferLength);

                        pipeline.Enqueue(frame);
                    }

            FPS     = pipeline.Timer.FPS;
            BackLog = pipeline.Count;
        }
        public void AddFrame(Vector3[] vertices, Texture2D colourTexture, Vector2[] uvs, float frameDeltaTime)
        {
            // If the frame count has reached its limit, throw an exception
            if (frameIndex >= MaxFramesCount)
            {
                throw new FrameStoreFullException("Frame count is equal to the maximum");
            }

            // Then, extract the depth of each vertex into a float array and convert
            // the uv coordinates list into a list of objects that can be serialized
            float[] depthData = new float[vertices.Length];
            KinectFrame.SerializableVector2[] serializableUvs = new KinectFrame.SerializableVector2[uvs.Length];

            // The vertex and uv arrays are the same length, so the new arrays can be
            // populated in the same for loop
            for (int i = 0; i < vertices.Length; i++)
            {
                depthData[i]       = vertices[i].z;
                serializableUvs[i] = new KinectFrame.SerializableVector2(uvs[i]);
            }

            // Create a new Kinect frame using the data and add it to the storage object. Encode
            // the colour texture as a JPEG to reduce file size
            frames[frameIndex++] = new KinectFrame(depthData,
                                                   ImageConversion.EncodeToJPG(colourTexture),
                                                   serializableUvs,
                                                   frameDeltaTime);
        }
示例#4
0
        private AnimationKey KinectFrameToKeyFrame_Old(KinectFrame frame)
        {
            var keyFrame = new AnimationKey();

            //Go through all the joints in a single frame 
            //and add the rotation in that frame to a key frame for the animation
            foreach (var kinectjoint in frame.Joints)
            {
                LinkedJoints[kinectjoint.Key].LocalMatrix = kinectjoint.Value.HierarchicalRotation;
            }

            var mat = Matrix.Identity;
            foreach (var animationJoint in LinkedJoints.Values)
            {
                if (animationJoint.IsValid)
                {
                    mat = animationJoint.LocalMatrix;
                    keyFrame.BoneTransforms.Add(mat);
                }
                else
                {
                    keyFrame.BoneTransforms.Add(mat);

                }

            }

            return keyFrame;
        }
示例#5
0
 public RemoveSingleFrame(KinectRecording rec, int index)
 {
     _recording = rec;
     _index     = index;
     _frame     = _recording.GetFrame(_index);
     Execute();
 }
示例#6
0
        public static bool[] ComputeFreeSpace(KinectFrame frame, float threshold)
        {
            if (frame != null)
            {
                var depthImage  = frame.DepthImage;
                var frameWidth  = frame.Sensor.DepthStream.FrameWidth;
                var frameHeight = frame.Sensor.DepthStream.FrameHeight;
                var result      = new bool[frameWidth];
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = true;
                }

                for (int i = 0; i < frameHeight; i += 1)
                {
                    for (int j = 0; j < frameWidth; j += 1)
                    {
                        // depth in millimeters
                        var depth = ((ushort)depthImage[i * frameWidth + (frameWidth - j - 1)]) >> 3;
                        if (depth < threshold)
                        {
                            result[j] = false;
                        }
                    }
                }

                return(result);
            }

            return(null);
        }
示例#7
0
        private ImageSource GetBitmapSourceFromFrame(IDisposable frame)
        {
            KinectFrame kFrame = new KinectFrame(frame);

            int width    = kFrame.FrameDescription().Width;
            int height   = kFrame.FrameDescription().Height;
            int minDepth = (frame is DepthFrame) ? (frame as DepthFrame).DepthMinReliableDistance : 0;
            int maxDepth = (frame is DepthFrame) ? (frame as DepthFrame).DepthMaxReliableDistance : 0;

            UInt16[] shortPixels = new UInt16[width * height];
            byte[]   bytePixels  = kFrame.getPixelArray();

            if (frame is ColorFrame)
            {
                kFrame.CopyRawFrameToArray(bytePixels);
            }
            else
            {
                kFrame.CopyFrameDataToArray(shortPixels);

                int colorIndex = 0;
                for (int index = 0; index < shortPixels.Length; ++index)
                {
                    UInt16 pixel     = shortPixels[index];
                    byte   intensity = (byte)((frame is InfraredFrame) ? (pixel >> 8) : (pixel >= minDepth && pixel <= maxDepth) ? pixel : 0);

                    bytePixels[colorIndex++] = intensity;
                    bytePixels[colorIndex++] = intensity;
                }
            }
            return(BitmapSource.Create(width, height, 96, 96, kFrame.PixelFormat(), null, bytePixels, kFrame.Stride()));
        }
        /// <summary>
        /// Draws the frame given
        /// </summary>
        public void Draw(KinectFrame frameToDraw)
        {
            if (frameToDraw == null)
            {
                Debug.Log(LogLevel.Warning, "No Frame Available!");
                return;
            }

            if (_drawInstance == null)
            {
                return;
            }

            _drawInstance.SetFrame(frameToDraw);
            _drawInstance.Draw();
            //_drawGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, 640, 480 ));
        }
示例#9
0
    public bool ApplyNextFrame(MeshRenderer targetMesh, ComputeBuffer targetBuffer)
    {
        if (source.frames.First == null)
        {
            return(false);
        }

        KinectFrame currentFrame = source.frames.First.Value;

        switch (currentFrame.frameState)
        {
        case KinectFrameState.Decompressed:
            Material matt = targetMesh.material;
            targetBuffer.SetData(currentFrame.decompressedData);
            source.frames.RemoveFirst();
            matt.SetBuffer("colors", targetBuffer);
            matt.SetInt("_MatrixX", source.matrixSize.x);
            matt.SetInt("_MatrixY", source.matrixSize.y);
            matt.SetInt("_MatrixZ", source.matrixSize.z);
            return(true);

        case KinectFrameState.PartiallyPopulated:
            droppedFrames++;
            print("Discarding partial frame " + currentFrame.frameNumber + " ( " + droppedFrames + " total dropped frames)");
            source.frames.RemoveFirst();
            return(false);

        case KinectFrameState.Error:
            errorFrames++;
            print("Discarding error frame " + currentFrame.frameNumber + " ( " + errorFrames + " total error frames)");
            source.frames.RemoveFirst();
            return(false);

        default:
            return(false);
        }
    }
 public void Record(KinectFrame currFrame)
 {
     _recording.AddFrame(currFrame);
 }
示例#11
0
 public void SetFrame(KinectFrame frame)
 {
     _kinectFrame = frame;
 }
示例#12
0
        public void OnKinectFrame(KinectFrame kinectFrame)
        {
            _dispatcher.BeginInvoke((Action)(() =>
            {
                String skeletonsMsg = "People: ";

                foreach (Button button in personButton)
                {
                    button.Content = "";
                    button.Visibility = System.Windows.Visibility.Hidden;
                }

                for (int i = 0; i < 6; i++)
                {
                    Skeleton skeleton = kinectFrame.SkeletonData.ElementAt(i);

                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        foreach (Joint joint in skeleton.Joints)
                        {
                            if (joint.JointType == JointType.Head)
                            {
                                personButton[i].Content = skeleton.TrackingId;
                                personButton[i].Visibility = System.Windows.Visibility.Visible;

                                Joint scaledJoint = joint.ScaleTo(320, 240, .3f, .3f);

                                Canvas.SetLeft(personButton[i], scaledJoint.Position.X - (personButton[i].Width / 2));
                                Canvas.SetTop(personButton[i], scaledJoint.Position.Y);

                                skeletonsMsg += String.Format("{0}({1}|{2});", skeleton.TrackingId, joint.Position.X, joint.Position.Y);
                            }
                        }

                        if (skeleton.TrackingId == selectedTrackingId)
                        {
                            if (skeleton.Position.Z < 1)
                            {
                                SetDirection('s', "Skeleton");
                            }
                            else if (skeleton.Position.Z > 1.5)
                            {
                                SetDirection('w', "Skeleton");
                            }
                            else if (skeleton.Position.X < -.2f)
                            {
                                SetDirection('d', "Skeleton");
                            }
                            else if (skeleton.Position.X > -.2f && skeleton.Position.X < .2f)
                            {
                                SetDirection('p', "Skeleton");
                            }
                            else if (skeleton.Position.X > .2f)
                            {
                                SetDirection('a', "Skeleton");
                            }
                        }
                    }
                }

                if (reportSkeletons)
                {
                    if (comboBoxSelectedUser.SelectedItem != null && checkBoxSendBumperMessage.IsChecked == true)
                    {
                        skype.SendMessage(comboBoxSelectedUser.SelectedItem.ToString(), skeletonsMsg);
                    }

                    reportSkeletons = false;
                }
            }));
        }