示例#1
0
        private UnitTests.Viper.Sample.viper deserialiseObject(string filename)
        {
            log.Debug("deserializeObject: Reading with XmlReader");
            // Create an instance of the XmlSerializer specifying type and namespace.
            XmlSerializer serializer = new XmlSerializer(typeof(UnitTests.Viper.Sample.viper));
            // A FileStream is needed to read the XML document.
            FileStream fs     = new FileStream(filename, FileMode.Open);
            XmlReader  reader = new XmlTextReader(fs);

            // Declare an object variable of the type to be deserialized & use the Deserialize method to restore the object's state.
            UnitTests.Viper.Sample.viper vt = (UnitTests.Viper.Sample.viper)serializer.Deserialize(reader);
            reader.Close();
            fs.Close();
            return(vt);
        }
示例#2
0
        private IEnumerable <IMediaSequence> viperLabelledFeatures()
        {
            List <IMediaSequence> mediaSequence = new List <IMediaSequence>();

            UnitTests.Viper.Sample.viper vt = deserialiseObject(_viperDataFilename);

            List <KeyValuePair <string, string> > possibleAttributes = new List <KeyValuePair <string, string> >();

            foreach (object o in vt.Items)
            {
                if (o is viperConfig)
                {
                    // Extract a list of all the possible attributes for all the possible objects.
                    // This does make an assumption that they are all uniquely named, and all apply to all frames.
                    // This assumption is not valid generally, but is OK for our situation
                    viperConfig vc = ( viperConfig )o;
                    foreach (viperConfigDescriptor d in vc.descriptor)
                    {
                        if (d.type.CompareTo("OBJECT") == 0)
                        {
                            possibleAttributes.AddRange(extractViperSampleTypes(d.attribute));
                        }
                    }
                }
            }
            // Now we have compiled a list of all possible attributes for all possible objects

            // Go through the viperData itself now & extract the individual items
            foreach (object o in vt.Items)
            {
                if (o is viperData)
                {
                    //
                    log.Debug("Found the viperData");
                    viperData vd = (UnitTests.Viper.Sample.viperData)o;

                    foreach (viperDataSourcefile vsf in vd.sourcefile)
                    {
                        String filenameFrameImages = null;
                        filenameFrameImages = vsf.filename;
                        viperDataSourcefileFile vsff = extractViperDataSourceFileFile(vsf.file, "Information");
                        long?numFrames = extractAttributeLong(vsff.attribute, "NUMFRAMES");

                        // Loop through all the objects
                        foreach (viperDataSourcefileObject sfo in vsf.@object)
                        {
                            // Go through each of the named attributes
                            foreach (KeyValuePair <string, string> kvp in possibleAttributes)
                            {
                                attribute a = extractAttribute(sfo.attribute, kvp.Key);
                                if (a != null)
                                {
                                    // Get all the points & add them to the relevant MediaSequence entries for that named attribute
                                    bool extracted = false;

                                    // have to do it based on the type obtained in kvp.Value
                                    if (kvp.Value.CompareTo("http://lamp.cfar.umd.edu/viperdata#point") == 0)
                                    {
                                        if (a.point == null)
                                        {
                                            log.Debug("Unable to properly extract the attribute");
                                        }
                                        else
                                        {
                                            // The problem here is that we only seem to be seeing the first point



                                            // ... TODO ...

                                            // Pull out a point version
                                            // ...
                                            // Mark as dealt with
                                            extracted = true;
                                        }
                                    }

                                    if (kvp.Value.CompareTo("http://lamp.cfar.umd.edu/viperdata#bbox") == 0)
                                    {
                                        if (a.point == null)
                                        {
                                            log.Debug("Unable to properly extract the attribute");
                                        }
                                        else
                                        {
                                            // ... TODO ...

                                            // Pull out a bounding box version
                                            // ...
                                            // Mark as dealt with
                                            extracted = true;
                                        }
                                    }

                                    if (kvp.Value.CompareTo("http://lamp.cfar.umd.edu/viperdata#circle") == 0)
                                    {
                                        if (a.point == null)
                                        {
                                            log.Debug("Unable to properly extract the attribute");
                                        }
                                        else
                                        {
                                            // ... TODO ...

                                            // Pull out a circle version
                                            // ...
                                            // Mark as dealt with
                                            extracted = true;
                                        }
                                    }

                                    // ... TODO ...
                                }
                            }
                        }

                        // Now go to the next source file level (source file is actually a list of image files)
                    }
                }
            }



            UnitTests.Viper.Schema.viper vtt = UnitTests.Viper.Schema.viper.LoadFromFile(_viperDataFilename);

            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);
        }