public static FaceFeaturesDB ReadCSV(string filename, string delim = ",") { var db = new FaceFeaturesDB(); using (var csvreader = new CsvReader(new StreamReader(filename), true)) { var headers = csvreader.GetFieldHeaders(); while (csvreader.ReadNextRecord()) { var metdata = PhotoMetadataCsv.Deserializer(filename, csvreader); var features = new FaceFeatures( new ComponentFeature(ParseEscapedVector(csvreader[3]), 0), new ComponentFeature(ParseEscapedVector(csvreader[4]), 0), new ComponentFeature(ParseEscapedVector(csvreader[5]), 0), new ComponentFeature(ParseEscapedVector(csvreader[6]), 0), new ComponentFeature(ParseEscapedVector(csvreader[7]), 0), ParseEscapedVector(csvreader[8]) ); db.AddPhotoFeatures(metdata, features); } } return(db); }
public static void SaveCSV(string csvFile, FaceFeaturesDB face, string delim = ",") { using (var writer = new StreamWriter(csvFile)) { writer.WriteLine(string.Join(delim, columnNames)); foreach (var entry in face.Entries) { var metadata = string.Join(delim, PhotoMetadataCsv.Serializer(entry.Item1, Path.GetFullPath(csvFile))); writer.Write(string.Join(delim, metadata, Escape(string.Join(";", entry.Item2.Hair.Features)), Escape(string.Join(";", entry.Item2.Eyebrows.Features)), Escape(string.Join(";", entry.Item2.Eyes.Features)), Escape(string.Join(";", entry.Item2.Nose.Features)), Escape(string.Join(";", entry.Item2.Mouth.Features)), Escape(string.Join(";", entry.Item2.Shape)) )); writer.WriteLine(); } writer.Flush(); writer.Close(); } }