示例#1
0
        void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            // Get a reference to the multi-frame
            var reference = e.FrameReference.AcquireFrame();

            //stores color and depth frame by frame to outside source
            using (var colorframe = reference.ColorFrameReference.AcquireFrame())
            {
                using (var depthframe = reference.DepthFrameReference.AcquireFrame())
                {
                    if (colorframe != null && depthframe != null)
                    {
                        // Do something with the frame...
                        if (_mode == Mode.Record && StartSavingFrames)
                        {
                            //BitmapSource colorbitmap = ToBitmap1(colorframe);
                            //BitmapSource depthbitmap = ToBitmap1(depthframe);


                            //SaveColorTimestamps.AddLast(DateTime.Now.ToString("hhmmssfff"));
                            //SaveColorFrames.AddLast(colorbitmap);
                            String formated_date = (DateTime.Now - DateTime.Parse("1/1/1970 0:0:0")).TotalMilliseconds.ToString();
                            //SaveDepthTimestamps.AddLast(formated_date);
                            //SaveDepthFrames.AddLast(depthbitmap);


                            BitmapSource combinedbitmap = ToCombinedData(colorframe, depthframe, formated_date);
                            SaveCombinedTimestamps.AddLast(formated_date);
                            SaveCombinedFrames.AddLast(combinedbitmap);

                            //string temppath = System.IO.Path.Combine(@"../output/kinect/depthmatrix/", formated_date + ".txt");
                            //File.WriteAllLines(temppath, full_pixelData.Select(d => d.ToString()));
                            //System.IO.File.WriteAllBytes(temppath, full_pixelData);
                        }
                    }
                }
            }
            if (isShown == true)
            {
                // Open color frame
                using (var frame = reference.ColorFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        // Do something with the frame...
                        if (_mode == Mode.Color)
                        {
                            BitmapSource bitmap = ToBitmap1(frame);
                            RGBVideo.Image = BitmapFromSource(bitmap);
                        }
                    }
                }

                // Open depth frame
                using (var frame = reference.DepthFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        // Do something with the frame...
                        if (_mode == Mode.Depth)
                        {
                            BitmapSource bitmap = ToBitmap1(frame);
                            DepthVideo.Image = BitmapFromSource(bitmap);
                        }
                    }
                }

                // Open infrared frame
                using (var frame = reference.InfraredFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        // Do something with the frame...
                        if (_mode == Mode.Infrared)
                        {
                        }
                    }
                }
            }
        }
示例#2
0
        public void kill()
        {
            StartSavingFrames = false;
            _mode             = Mode.Stop;

            /*
             * IEnumerator<String> a = SaveColorTimestamps.GetEnumerator();
             * foreach (BitmapSource node in SaveColorFrames)
             * {
             *  a.MoveNext();
             *  PngBitmapEncoder enc = new PngBitmapEncoder();
             *  enc.Frames.Add(BitmapFrame.Create(node));
             *  string temppath = System.IO.Path.Combine(@"../output/kinect/color/", a.Current + ".png");
             *  using (System.IO.FileStream fs = new System.IO.FileStream(temppath, System.IO.FileMode.Create))
             *  {
             *      enc.Save(fs);
             *      fs.Close();
             *  }
             * }
             * SaveColorTimestamps.Clear();
             * SaveColorFrames.Clear();
             *
             * a.Dispose();
             * a = SaveDepthTimestamps.GetEnumerator();
             * foreach (BitmapSource node in SaveDepthFrames)
             * {
             *  a.MoveNext();
             *  PngBitmapEncoder enc = new PngBitmapEncoder();
             *  enc.Frames.Add(BitmapFrame.Create(node));
             *  string temppath = System.IO.Path.Combine(@"../output/kinect/depth/", a.Current + ".png");
             *  using (System.IO.FileStream fs = new System.IO.FileStream(temppath, System.IO.FileMode.Create))
             *  {
             *      enc.Save(fs);
             *      fs.Close();
             *
             *  }
             *
             * }
             * SaveDepthTimestamps.Clear();
             * SaveDepthFrames.Clear();
             * this.Close();
             */
            IEnumerator <String> a = SaveDepthTimestamps.GetEnumerator();

            foreach (BitmapSource node in SaveDepthFrames)
            {
                a.MoveNext();
                PngBitmapEncoder enc = new PngBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create(node));
                string temppath = System.IO.Path.Combine(@"../output/kinect/depth/", a.Current + ".png");
                using (System.IO.FileStream fs = new System.IO.FileStream(temppath, System.IO.FileMode.Create))
                {
                    enc.Save(fs);
                    fs.Close();
                }
            }
            a.Dispose();

            SaveDepthTimestamps.Clear();
            SaveDepthFrames.Clear();

            a = SaveCombinedTimestamps.GetEnumerator();
            foreach (BitmapSource node in SaveCombinedFrames)
            {
                a.MoveNext();
                PngBitmapEncoder enc = new PngBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create(node));
                string temppath = System.IO.Path.Combine(@"../output/kinect/color/", a.Current + ".png");
                using (System.IO.FileStream fs = new System.IO.FileStream(temppath, System.IO.FileMode.Create))
                {
                    enc.Save(fs);
                    fs.Close();
                }
            }

            SaveCombinedTimestamps.Clear();
            SaveCombinedFrames.Clear();

            a.Dispose();


            a = SaveXYZTimestamps.GetEnumerator();
            foreach (CameraSpacePoint[] node in SaveCameraSpacePoints)
            {
                a.MoveNext();
                string temppath = System.IO.Path.Combine(@"../output/kinect/XYZmatrix/", a.Current + ".txt");
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(temppath, true))
                {
                    for (int depthY = 0; depthY < height; depthY++)
                    {
                        for (int depthX = 0; depthX < width; depthX++)
                        {
                            int depthIndex = depthY * width + depthX;

                            float x = node[depthIndex].X;
                            float y = node[depthIndex].Y;
                            float z = node[depthIndex].Z;

                            file.WriteLine("{0:.4f} {1:.4f} {2:.4f},", x.ToString(), y.ToString(), z.ToString());
                        }
                    }
                }
            }
            a.Dispose();


            a = SaveDepthMatrixTimestamp.GetEnumerator();
            foreach (ushort[] node in SaveDepthMatrix)
            {
                a.MoveNext();
                string temppath = System.IO.Path.Combine(@"../output/kinect/depthmatrix/", a.Current + ".txt");
                File.WriteAllLines(temppath, node.Select(d => d.ToString()));
            }
            SaveDepthMatrixTimestamp.Clear();
            SaveDepthMatrix.Clear();

            a.Dispose();
            this.Close();
        }