Ejemplo n.º 1
0
    public void TestReadLine()
    {
      var datafile = "../../../data/TestReadLine.txt";

      using (FileStream fs = new FileStream(datafile, FileMode.Open))
      {
        Assert.AreEqual("Start\tLength\tKey", fs.ReadLine());
        Assert.AreEqual("55\t1279\tS1,255", fs.ReadLine());
        Assert.AreEqual("1334\t1383\tS2,355", fs.ReadLine());
        Assert.AreEqual(null, fs.ReadLine());
      }
    }
Ejemplo n.º 2
0
 public static string LoadFlie(string filename)
 {
     try {
         using (var file = new FileStream(filename,FileMode.Open,FileAccess.Read)) {
             return file.ReadLine();
         }
     }
     catch (IOException e) {
         return "sorry cant open file";
     }
 }
Ejemplo n.º 3
0
        // Note: In order to see the full range of depth (including the less reliable far field depth) we are setting maxDepth (ushort.MaxValue) to the extreme potential depth threshold
        // If you wish to filter by reliable depth distance, use:  depthFrame.DepthMaxReliableDistance
        private unsafe void ProcessDepthFrameData(IntPtr depthFrameData, int frameSize, ushort minDepth, ushort maxDepth, DepthSpacePoint p, bool rec, bool left)
        {
            string file = "";
            if (depthFrameSelector == 15 && rec)
            {
                if (left) 
                    file = String.Format("c:/temp/SLRS/hands/depthDataLeft_{0}_{1}_{2}.txt", gestureWord[gestureNumber], sequenceID, depthFrameIndexL++);
                else
                    file = String.Format("c:/temp/SLRS/hands/depthDataRight_{0}_{1}_{2}.txt", gestureWord[gestureNumber], sequenceID, depthFrameIndexR++);

                depthData = new StreamWriter(file, true);
                Helper.writePCDHeader(depthData);
            }

            ushort* frameData = (ushort*)depthFrameData; // depth frame data is a 16 bit value
            ushort initDepth = frameData[depthFrameDescription.Width * ((int)p.Y) + ((int)p.X)];
            byte initPos = (byte)(initDepth / MapDepthToByte);

            int cloudPointCount = 0;
            int factor = 80;
            int index = 0;
            for (int y = -frameSize; y < frameSize; y++)
            {
                for (int x = -frameSize; x < frameSize; x++)
                {                    
                    //Select index for smaller frame and get Depth value
                    int i = (depthFrameDescription.Width * ((int)p.Y + y) + ((int)p.X + x));
                    ushort depth = frameData[i];

                    // if this depth is near to the initpoint (handpalm) --> record and adapt depth map for visualization
                    if (depth < initDepth + factor && depth > initDepth - factor)
                    {
                        if (depthFrameSelector == 15 && rec)
                        {
                            var point = Helper.depthToPCD(frameSize, p.X + x, p.Y + y, depth);
                            depthData.WriteLine(String.Format("{0} {1} {2}", point.X, point.Y, point.Z));
                            cloudPointCount++;
                        }

                        depth += (ushort)((depth - initDepth) * 10);
                    }
                    else
                        depth = 0;

                    this.depthPixels[index++] = (byte)(depth / MapDepthToByte);
                    //byte greyValue = (byte)(depth >= minDepth && depth <= maxDepth ? (depth / MapDepthToByte) : 0);
                    //this.depthPixels[index++] = (byte)greyValue;//(255 - greyValue);
                }
            }

            if (depthFrameSelector == 15 && rec)
            {
                depthData.Flush();
                depthData.Close();

                FileStream fs = new FileStream(file);
                string heigth = cloudPointCount.ToString();
                while (!fs.EndOfStream)
                {
                    var line = fs.ReadLine();
                    if (line.Contains("WIDTH"))
                        fs.Write(Encoding.ASCII.GetBytes(height), fs.Position+1, height.Lenght);
                    if (line.Contains("POINTS")) {
                        fs.Write(Encoding.ASCII.GetBytes(height), fs.Position+1, height.Lenght);
                        break;
                    }
                }

                fs.Flush();
                fs.Close();

                depthFrameSelector = 0;
            }

            if (rec) depthFrameSelector++;
        }