Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //StreamReader reader = new StreamReader("c:\\tmp\\en.yml");
            StreamReader reader = new StreamReader("c:\\tmp\\de.yml");

            TextInput input = new TextInput(reader.ReadToEnd());

            bool success;
            YamlParser parser = new YamlParser();
            YamlStream yamlStream = parser.ParseYamlStream(input, out success);
            if (success)
            {
                foreach (YamlDocument doc in yamlStream.Documents)
                {
                    TreeNode rootNode = YamlEmittor.CreateNode(doc.Root);
                    treeView1.Nodes.Add(rootNode);

                    foreach (TreeNode node in rootNode.Nodes)
                    {
                        richTextBox1.AppendText(node.Text);
                    }
                }
            }
            else
            {
                richTextBox1.Text = parser.GetErrorMessages();
            }
        }
 public static YamlStream Load(string file)
 {
     string text = File.ReadAllText(file);
     TextInput input = new TextInput(text);
     YamlParser parser = new YamlParser();
     bool success;
     YamlStream stream = parser.ParseYamlStream(input, out success);
     if (success)
     {
         return stream;
     }
     else
     {
         string message = parser.GetEorrorMessages();
         throw new Exception(message);
     }
 }
Пример #3
0
        public static YamlStream Load(string file)
        {
            string     text   = File.ReadAllText(file);
            TextInput  input  = new TextInput(text);
            YamlParser parser = new YamlParser();
            bool       success;
            YamlStream stream = parser.ParseYamlStream(input, out success);

            if (success)
            {
                return(stream);
            }
            else
            {
                string message = $"Problem with file '{file}', probably at line #{parser.GetProbableErrorLine()}";
                throw new Exception(message);
            }
        }
Пример #4
0
        public static YamlStream Load(string file)
        {
            string     text   = File.ReadAllText(file);
            TextInput  input  = new TextInput(text);
            YamlParser parser = new YamlParser();
            bool       success;
            YamlStream stream = parser.ParseYamlStream(input, out success);

            if (success)
            {
                return(stream);
            }
            else
            {
                string message = parser.GetEorrorMessages();
                throw new Exception(message);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets the sample yaml.
        /// </summary>
        /// <returns></returns>
        public List<MappingEntry> GetSampleYaml()
        {
            YamlParser parser = new YamlParser();
            TextInput input = new TextInput(File.ReadAllText("sample.txt"));
            bool success;
            YamlStream yamlStream = parser.ParseYamlStream(input, out success);
            if (success)
            {

                    Mapping mapping = yamlStream.Documents[0].Root as Mapping;

                    return mapping.Enties;
            }
            else
            {
                Console.WriteLine(parser.GetEorrorMessages());
            }

            return null;
        }
        private void toolStripButtonParse_Click(object sender, EventArgs e)
        {
            TextInput input = new TextInput(richTextBoxSource.Text);

            bool success;
            YamlParser parser = new YamlParser();
            YamlStream yamlStream = parser.ParseYamlStream(input, out success);
            if (success)
            {
                treeViewData.Nodes.Clear();
                foreach (YamlDocument doc in yamlStream.Documents)
                {
                    treeViewData.Nodes.Add(YamlEmittor.CreateNode(doc.Root));
                }
                treeViewData.ExpandAll();
                tabControl1.SelectedTab = tabPageDataTree;
            }
            else
            {
                MessageBox.Show(parser.GetEorrorMessages());
            }
        }
Пример #7
0
        private IEnumerable<IMediaSequence> putFaceLabelledFeatures()
        {
            List<IMediaSequence> mediaSequence = new List<IMediaSequence>();

            for ( int subject = 1; subject <= 100; subject++ )
            {
                string region1BaseDirectory = directory() + "/regions/R" + subject.ToString( "000" );
                string region2BaseDirectory = directory() + "/regions2/R" + subject.ToString( "000" );
                string landmarkBaseDirectory = directory() + "/landmarks/L" + subject.ToString( "000" );
                string landmark2BaseDirectory = directory() + "/landmarks2/L" + subject.ToString( "000" );
                string contourBaseDirectory = directory() + "/contours/C" + subject.ToString( "000" );

                string imageBaseDirectory = directory() + "/images/0" + subject.ToString( "000" );

                DirectoryInfo region1Dir = new DirectoryInfo( region1BaseDirectory );
                DirectoryInfo region2Dir = new DirectoryInfo( region2BaseDirectory );
                DirectoryInfo landmarkDir = new DirectoryInfo( landmarkBaseDirectory );
                DirectoryInfo landmark2Dir = new DirectoryInfo( landmark2BaseDirectory );
                DirectoryInfo contourDir = new DirectoryInfo( contourBaseDirectory );

                FileInfo[] region1Files = region1Dir.GetFiles( "*.yml" );
                foreach ( FileInfo region1FileInfo in region1Files )
                {
                    string imageFilename = imageBaseDirectory + "/" + region1FileInfo.Name.Replace( ".yml", ".JPG" );
                    bool imageFileFound = File.Exists( imageFilename );

                    string region2Filename = region2BaseDirectory + "/" + region1FileInfo.Name;
                    bool region2FileFound = File.Exists( region2Filename );

                    string landmarkFilename = landmarkBaseDirectory + "/" + region1FileInfo.Name;
                    bool landmarkFileFound = File.Exists( landmarkFilename );

                    string landmark2Filename = landmark2BaseDirectory + "/" + region1FileInfo.Name;
                    bool landmark2FileFound = File.Exists( landmark2Filename );

                    string contourFilename = contourBaseDirectory + "/" + region1FileInfo.Name;
                    bool contourFileFound = File.Exists( contourFilename );

                    if ( contourFileFound )
                    {
                        contourFiles++;
                    }

                    if ( !imageFileFound )
                    {
                        missingFiles++;
                        break;
                    }

                    if ( !region2FileFound )
                    {
                        // Have Region 1 file, have image file, but missing Region 2 file
                        missingFiles++;
                        break;
                    }

                    if ( !landmarkFileFound )
                    {
                        // Have Region 1 file, Region 2 file, have image file, but missing Landmark file
                        missingFiles++;
                        break;
                    }

                    if ( !landmark2FileFound )
                    {
                        // Have Region 1 file, Region 2 file, have image file, but missing Landmark file
                        missingFiles++;
                        break;
                    }

                    // We have the corresponding image file, now we actually need to load and process all 3 YAML files (which also exist)
                    bool successRegion1 = false;
                    bool successRegion2 = false;
                    bool successLandmark = false;
                    bool successLandmark2 = false;
                    bool successContour = false;
                    YamlParser parser = new YamlParser();

                    TextInput inputRegion1 = new TextInput( yamlPreprocessor( File.ReadAllText( region1FileInfo.FullName ) ) );
                    YamlStream yamlStreamRegion1 = parser.ParseYamlStream( inputRegion1, out successRegion1 );
                    if ( !successRegion1 )
                    {
                        yamlErrors++;
                    }

                    TextInput inputRegion2 = new TextInput( yamlPreprocessor( File.ReadAllText( region2Filename ) ) );
                    YamlStream yamlStreamRegion2 = parser.ParseYamlStream( inputRegion2, out successRegion2 );
                    if ( !successRegion2 )
                    {
                        yamlErrors++;
                    }

                    TextInput inputLandmark = new TextInput( yamlPreprocessor( File.ReadAllText( landmarkFilename ) ) );
                    YamlStream yamlStreamLandmark = parser.ParseYamlStream( inputLandmark, out successLandmark );
                    if ( !successLandmark )
                    {
                        yamlErrors++;
                    }

                    TextInput inputLandmark2 = new TextInput( yamlPreprocessor( File.ReadAllText( landmark2Filename ) ) );
                    YamlStream yamlStreamLandmark2 = parser.ParseYamlStream( inputLandmark2, out successLandmark2 );
                    if ( !successLandmark2 )
                    {
                        yamlErrors++;
                    }

                    TextInput inputContour;
                    YamlStream yamlStreamContour = null;
                    if ( contourFileFound )
                    {
                        inputContour = new TextInput( yamlPreprocessor( File.ReadAllText( contourFilename ) ) );
                        yamlStreamContour = parser.ParseYamlStream( inputContour, out successContour );
                    }

                    if ( successRegion1 || successRegion2 || successLandmark || successLandmark2 || successContour )
                    {
                        // Create a container for the particular features which are labelled in the YAML
                        List<ILabelledFeature> features = new List<ILabelledFeature>();

                        if ( successRegion1 )
                        {
                            // features.AddRange( extractRegionsFromYaml( yamlStreamRegion1 ) );
                        }
                        if ( successRegion2 )
                        {
                            features.AddRange( extractRegionsFromYaml( yamlStreamRegion2 ) );
                        }
                        if ( successLandmark )
                        {
                            // features.AddRange( extractPointsFromYaml( yamlStreamLandmark ) );
                        }
                        if ( successLandmark2 )
                        {
                            features.AddRange( extractPointsFromYaml( yamlStreamLandmark2 ) );
                        }
                        if ( successContour )
                        {
                            features.AddRange( extractContoursFromYaml( yamlStreamContour ) );
                        }

                        // This frame has the two eye features from above, plus the regions as well
                        IMediaFrame mediaFrame = new LazyLoadImageMediaFrame( imageFilename, features );

                        // This mediaFrame sequence only has the one frame in it
                        mediaSequence.Add( new SingleFrameMediaSequence( getName() + "_subject" + subject.ToString( "000" ), mediaFrame ) );
                    }

                }
            }
            Assert.LessOrEqual( missingFiles, 1, "More than expected number of image files were not found (expected 1)" );
            Assert.LessOrEqual( yamlErrors, 0, "More than expected number of YAML errors occurred (expected 0)" );
            Assert.AreEqual( 2182, contourFiles, "Wrong number of contour files found (expected 2182, although doco says 2193)" );
            Assert.LessOrEqual( regionAllZero, 24457, "More than expected number of regionAllZero occurred (expected 24468)" );
            Assert.LessOrEqual( notFoundRegionCorners, 0, "More than expected number of notFoundRegionCorners occurred (expected 0)" );
            Assert.LessOrEqual( unrecognisedFeatureName, 0, "More than expected number of unrecognisedFeatureName occurred (expected 0)" );
            return mediaSequence;
        }
Пример #8
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            richTextBox1.Visible = false;
            treeView1.Visible = true;

            StreamReader reader = new StreamReader(fileName);

            TextInput input = new TextInput(reader.ReadToEnd());

            bool success;
            YamlParser parser = new YamlParser();
            YamlStream yamlStream = parser.ParseYamlStream(input, out success);
            if (success)
            {

                foreach (YamlDocument doc in yamlStream.Documents)
                {
                    TreeNode rootNode = YamlEmittor.CreateNode(doc.Root);
                    treeView1.Nodes.Add(rootNode);

                    ProcessTreeNode(rootNode);
                }

                tabControl1.SelectedIndex = 0;
            }
            else
            {
                treeView1.Visible = false;
                richTextBox1.Visible = true;
                richTextBox1.Text = parser.GetErrorMessages();
                tabControl1.SelectedIndex = 1;
                richTextBox1.Focus();
            }
            reader.Close();
        }