private static PhotoFingerPrintDatabaseWrapper LoadPhotoDatabase(string[] args) { IEnumerable <string> databaseFilePath = ConsoleUtils.GetArgumentTuple(args, "--photo-database"); if (databaseFilePath.Count() != 1) { throw new Exception("Photo database not provided or too many arguements provided"); } return(PhotoFingerPrintDatabaseLoader.Load(databaseFilePath.First())); }
private static void ExecuteSearch(string[] args) { string photoFile = GetPhotoPath(args); string databaseFile = GetDatabasePath(args); if (string.IsNullOrWhiteSpace(photoFile) || string.IsNullOrWhiteSpace(databaseFile)) { PrintHelp("Photo path or database path not provided"); return; } if (File.Exists(photoFile) == false) { PrintHelp("Photo file does not exist"); return; } if (File.Exists(databaseFile) == false) { PrintHelp("Database does not exist"); return; } using (Image frame = Image.FromFile(photoFile)) { PhotoFingerPrintDatabaseWrapper database = PhotoFingerPrintDatabaseLoader.Load(databaseFile); ulong imageHash = FrameIndexer.CalculateFramePerceptionHashOnly(frame); var results = from fingerPrint in database.PhotoFingerPrints.AsParallel() let distance = DistanceCalculator.CalculateHammingDistance(imageHash, fingerPrint.PHash) where distance < 5 orderby distance select new { Distance = distance, FilePath = fingerPrint.FilePath }; foreach (var result in results) { Console.WriteLine(string.Format("{0} - {1}", result.Distance, result.FilePath)); } } }
private static void ExecuteIndex(string[] args) { IEnumerable <string> photoFiles = GetPhotoPaths(args).Distinct(); string databaseFile = GetDatabasePath(args); if (photoFiles.Any() == false || string.IsNullOrWhiteSpace(databaseFile)) { PrintHelp("Photo file or database path not provided"); return; } PhotoFingerPrintDatabaseWrapper database = File.Exists(databaseFile) ? PhotoFingerPrintDatabaseLoader.Load(databaseFile) : new PhotoFingerPrintDatabaseWrapper(); IEnumerable <PhotoFingerPrintWrapper> fingerPrintBag = IndexPhotosImpl(photoFiles, database); database.PhotoFingerPrints = fingerPrintBag.ToArray(); PhotoFingerPrintDatabaseSaver.Save(database, databaseFile); }
public void TestPhotoIndexerSerialization() { var photoFingerPrint = new PhotoFingerPrintWrapper { FilePath = "test.png", PHash = 0x0A, EdgeGrayScaleThumb = new byte[] { 0, 1, 1 }, }; var database = new PhotoFingerPrintDatabaseWrapper { PhotoFingerPrints = new[] { photoFingerPrint }, }; using (var memoryStream = new MemoryStream()) { PhotoFingerPrintDatabaseSaver.Save(database, memoryStream); byte[] savedDatabase = memoryStream.ToArray(); PhotoFingerPrintDatabaseWrapper reloadedDatabase = PhotoFingerPrintDatabaseLoader.Load(savedDatabase); Assert.AreEqual(database, reloadedDatabase); } }