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; }
/// <summary> /// Extract all the images we can find that have labelled eyes and also a corresponding image file /// </summary> /// <param name="truthFilename"></param> /// <returns></returns> private IEnumerable <IMediaSequence> nirFaceLabelledFeatures(string truthFilename, List <string> imageDirectories) { long missingFiles = 0; string groundTruthDataFile = directory() + "/" + truthFilename; // In this case each media sequence in this list will simply contain a single MediaFrame with a null timestamp List <IMediaSequence> mediaSequence = new List <IMediaSequence>(); // create reader & open file TextReader tr = new StreamReader(groundTruthDataFile); String line = tr.ReadLine(); while (line != null) { // read a line of text String[] breakup = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string identifier = breakup[0].Replace(".bmp", ""); string imgSubdirectory = (breakup[0].Split('_'))[1]; bool fileFound = false; string imgFilename = null; foreach (string imageDirectory in imageDirectories) { imgFilename = directory() + "/" + imageDirectory + "/" + imgSubdirectory + "/" + (breakup[0].Replace(".bmp", ".jpg")); if (File.Exists(imgFilename)) { fileFound = true; break; } imgFilename = directory() + "/" + imageDirectory + "/" + imgSubdirectory + "_M_S/" + (breakup[0].Replace(".bmp", ".jpg")); if (File.Exists(imgFilename)) { fileFound = true; break; } imgFilename = directory() + "/" + imageDirectory + "/" + imgSubdirectory + "_M_B/" + (breakup[0].Replace(".bmp", ".jpg")); if (File.Exists(imgFilename)) { fileFound = true; break; } } if (fileFound) { // Create a container for these two eye features List <ILabelledFeature> features = new List <ILabelledFeature>(); // Pull out the point locations for each eye Point e1 = new Point(Convert.ToInt32(breakup[1]), Convert.ToInt32(breakup[2])); Point e2 = new Point(Convert.ToInt32(breakup[3]), Convert.ToInt32(breakup[4])); if (e1.X < e2.X) { // e1 is the right eye & e2 is the left eye features.Add(new LabelledFeature(DataSetEnums.FeatureName.RIGHT_EYE_CENTRE, new SinglePointPath(e1))); features.Add(new LabelledFeature(DataSetEnums.FeatureName.LEFT_EYE_CENTRE, new SinglePointPath(e2))); } else { features.Add(new LabelledFeature(DataSetEnums.FeatureName.RIGHT_EYE_CENTRE, new SinglePointPath(e2))); features.Add(new LabelledFeature(DataSetEnums.FeatureName.LEFT_EYE_CENTRE, new SinglePointPath(e1))); } // This frame has the two eye features from above IMediaFrame mediaFrame = new LazyLoadImageMediaFrame(imgFilename, features); // This mediaFrame sequence only has the one frame in it mediaSequence.Add(new SingleFrameMediaSequence(getName() + "_" + identifier, mediaFrame)); } else { missingFiles++; } line = tr.ReadLine(); } // close the stream tr.Close(); Assert.LessOrEqual(missingFiles, 2354, "More than expected number of image files were not found"); return(mediaSequence); }
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); }
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); }