Beispiel #1
0
        private void predictFrame(string file)
        {
            StreamReader      depthFile = new StreamReader(file);
            List <KinectData> depths    = new List <KinectData>();

            //LOAD KINECT DATA (X Y Z)
            while (!depthFile.EndOfStream)
            {
                var line = depthFile.ReadLine().Split(' ');
                if (line.Length > 1)
                {
                    var dat = new KinectData();
                    dat.X     = float.Parse(line[0]);
                    dat.Y     = float.Parse(line[1]);
                    dat.Depth = float.Parse(line[2]);
                    depths.Add(dat);
                }
            }
            depthFile.Close();

            //WRITE PREDICTION INPUT
            StreamWriter predictionInput = new StreamWriter(@"C:\temp\predictionInput.dat", false);

            predictionInput.WriteLine("f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 Class");

            float initDepth = depths[depths.Count / 2].Depth;

            for (int i = 0; i < depths.Count; i++)
            {
                string featStr = "";
                foreach (var o in offsets)
                {
                    float entry = 0;
                    if (i + o < 0 || i + o >= depths.Count)
                    {
                        entry = 0; // if out of bounds --> 0
                    }
                    else
                    {
                        float thisDepth = depths[i + o].Depth != 0.0f ? depths[i + o].Depth : depths[i].Depth;
                        entry = (depths[i].Depth - initDepth) / thisDepth;

                        if (float.IsInfinity(entry))
                        {
                            entry = 0; //Pixel invalid (infinite)
                        }
                    }
                    featStr += (entry.ToString().Replace(',', '.') + " ");
                }

                predictionInput.WriteLine(featStr + "0");
                predictionInput.Flush();
            }
            predictionInput.Close();

            //CREATE PREDICTION FILE
            predictFileRDF(new StringBuilder(@"C:\temp\predictionInput.dat"), new StringBuilder(forestDir));

            //READ PREDICTION FILE
            StreamReader sr          = new StreamReader(@"C:\Users\Martin\Documents\Visual Studio 2013\Projects\netica\SLRS\SLRS\bin\Debug\ranger.prediction");
            var          predictions = sr.ReadToEnd().Split(' ').ToList();

            sr.Close();
            predictions.Remove(predictions.First());

            //CREATE PCD FILE
            string       fileName    = file.Split('\\').Last();
            string       newFileName = fileName.Replace(".dth", ".pcd");
            string       newPath     = @"C:\temp\PCD\pcd\";
            StreamWriter pcdFile     = new StreamWriter(newPath + newFileName, false);

            for (int i = 0; i < predictions.Count; i++)
            {
                if (predictions[i] == "1")
                {
                    var point = Helper.depthToPCD(depths[i].X, depths[i].Y, depths[i].Depth);
                    pcdFile.WriteLine(String.Format("{0} {1} {2}", point.X.ToString().Replace(',', '.'), point.Y.ToString().Replace(',', '.'), point.Z.ToString().Replace(',', '.')));
                    pcdFile.Flush();
                }
            }

            pcdFile.Close();
        }
Beispiel #2
0
        private void predictFrame(string file)
        {
            StreamReader depthFile = new StreamReader(file);
            List<KinectData> depths = new List<KinectData>();

            //LOAD KINECT DATA (X Y Z)
            while (!depthFile.EndOfStream)
            {
                var line = depthFile.ReadLine().Split(' ');
                if (line.Length > 1)
                {
                    var dat = new KinectData();
                    dat.X = float.Parse(line[0]);
                    dat.Y = float.Parse(line[1]);
                    dat.Depth = float.Parse(line[2]);
                    depths.Add(dat);
                }
            }
            depthFile.Close();

            //WRITE PREDICTION INPUT
            StreamWriter predictionInput = new StreamWriter(@"C:\temp\predictionInput.dat",false);
            predictionInput.WriteLine("f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 Class");

            float initDepth = depths[depths.Count / 2].Depth;

            for (int i = 0; i < depths.Count ; i++)
            {
                string featStr = "";
                foreach (var o in offsets)
                {
                    float entry = 0;
                    if (i + o < 0 || i + o >= depths.Count)
                        entry = 0; // if out of bounds --> 0
                    else
                    {
                        float thisDepth = depths[i + o].Depth != 0.0f ? depths[i + o].Depth : depths[i].Depth;
                        entry = (depths[i].Depth - initDepth) / thisDepth;
                     
                        if (float.IsInfinity(entry))
                            entry = 0; //Pixel invalid (infinite)
                    }       
                    featStr += (entry.ToString().Replace(',', '.') + " ");
                }

                predictionInput.WriteLine(featStr + "0");
                predictionInput.Flush();
            }
            predictionInput.Close();

            //CREATE PREDICTION FILE
            predictFileRDF(new StringBuilder(@"C:\temp\predictionInput.dat"), new StringBuilder(forestDir));

            //READ PREDICTION FILE
            StreamReader sr = new StreamReader(@"C:\Users\Martin\Documents\Visual Studio 2013\Projects\netica\SLRS\SLRS\bin\Debug\ranger.prediction");
            var predictions = sr.ReadToEnd().Split(' ').ToList();
            sr.Close();
            predictions.Remove(predictions.First());

            //CREATE PCD FILE
            string fileName = file.Split('\\').Last();
            string newFileName = fileName.Replace(".dth", ".pcd");
            string newPath = @"C:\temp\PCD\pcd\";
            StreamWriter pcdFile = new StreamWriter(newPath + newFileName, false);

            for (int i=0; i< predictions.Count; i++)
            {
                if (predictions[i] == "1")
                {
                    var point = Helper.depthToPCD(depths[i].X, depths[i].Y, depths[i].Depth);
                    pcdFile.WriteLine(String.Format("{0} {1} {2}", point.X.ToString().Replace(',', '.'), point.Y.ToString().Replace(',', '.'), point.Z.ToString().Replace(',', '.')));
                    pcdFile.Flush();
                }
            }
            
            pcdFile.Close();
        }