public void TestDatabaseMetaTableSerialization()
        {
            var entry = new VideoFingerPrintDatabaseMetaTableEntryWrapper
            {
                FileName = "test",
                FileSize = 1,
            };

            var entry2 = new VideoFingerPrintDatabaseMetaTableEntryWrapper
            {
                FileName = "test 2",
                FileSize = 2,
            };

            var database = new VideoFingerPrintDatabaseMetaTableWrapper
            {
                DatabaseMetaTableEntries = new[] { entry, entry2 },
            };

            using (var memoryStream = new MemoryStream())
            {
                VideoFingerPrintDatabaseMetaTableSaver.Save(database, memoryStream);
                byte[] savedDatabase = memoryStream.ToArray();
                VideoFingerPrintDatabaseMetaTableWrapper reloadedDatabase = VideoFingerPrintDatabaseMetaTableLoader.Load(savedDatabase);

                Assert.AreEqual(database, reloadedDatabase);
            }
        }
Beispiel #2
0
        private static VideoFingerPrintDatabaseMetaTableWrapper CreateOrLoadMetatable(string metatablePath)
        {
            if (File.Exists(metatablePath))
            {
                return(VideoFingerPrintDatabaseMetaTableLoader.Load(metatablePath));
            }

            return(new VideoFingerPrintDatabaseMetaTableWrapper());
        }
Beispiel #3
0
        private static VideoFingerPrintDatabaseMetaTableWrapper LoadMetaTable(string[] args)
        {
            IEnumerable <string> databaseFilePath = ConsoleUtils.GetArgumentTuple(args, "--video-metatable");

            if (databaseFilePath.Count() != 1)
            {
                throw new Exception("Video metatable not provided or too many arguements provided");
            }

            return(VideoFingerPrintDatabaseMetaTableLoader.Load(databaseFilePath.First()));
        }
Beispiel #4
0
        private static void ExecuteCheckDatabase(string[] args)
        {
            string maxMemoryArg          = GetMaxMemory(args);
            string databaseMetaTablePath = GetDatabaseMetaTable(args);

            if (string.IsNullOrWhiteSpace(databaseMetaTablePath))
            {
                PrintHelp("Database metatable path not provided");
                return;
            }

            if (File.Exists(databaseMetaTablePath) == false)
            {
                PrintHelp("Database MetaTable does not exist");
                return;
            }

            if (string.IsNullOrWhiteSpace(maxMemoryArg))
            {
                PrintHelp("--max-memory must be set");
                return;
            }

            long maxMemory = 0;

            if (long.TryParse(maxMemoryArg, out maxMemory) == false)
            {
                PrintHelp("--max-memory could not be parsed");
                return;
            }

            VideoFingerPrintDatabaseMetaTableWrapper metaTable = VideoFingerPrintDatabaseMetaTableLoader.Load(databaseMetaTablePath);
            var random = new Random();

            foreach (string databasePath in metaTable.DatabaseMetaTableEntries.Select(e => e.FileName))
            {
                VideoFingerPrintDatabaseWrapper database = VideoFingerPrintDatabaseLoader.Load(databasePath);
                int videoFingerPrintSampleCount          = (int)Math.Round(database.VideoFingerPrints.Length / 3.0);
                IEnumerable <VideoFingerPrintWrapper> videoFingerPrints = from fingerPrint in database.VideoFingerPrints
                                                                          where random.Next() % 2 == 0
                                                                          select fingerPrint;

                foreach (VideoFingerPrintWrapper videoFingerPrint in videoFingerPrints.Take(videoFingerPrintSampleCount))
                {
                    VideoFingerPrintWrapper actualVideoFingerPrint = Video.VideoIndexer.IndexVideo(videoFingerPrint.FilePath, maxMemory);

                    if (Equals(videoFingerPrint, actualVideoFingerPrint) == false)
                    {
                        Console.WriteLine("{0} Fingerprint does not match", Path.GetFileName(videoFingerPrint.FilePath));
                    }
                }
            }
        }
Beispiel #5
0
        private static void ExecuteSearch(string[] args)
        {
            string photoFilePath         = GetPhotoPath(args);
            string databaseMetaTablePath = GetDatabaseMetaTable(args);

            if (string.IsNullOrWhiteSpace(photoFilePath) || string.IsNullOrWhiteSpace(databaseMetaTablePath))
            {
                PrintHelp("Photo path or database metatable path not provided");
                return;
            }

            if (File.Exists(photoFilePath) == false)
            {
                PrintHelp("Photo file does not exist");
                return;
            }

            if (File.Exists(databaseMetaTablePath) == false)
            {
                PrintHelp("Database MetaTable does not exist");
                return;
            }

            using (Image frame = Image.FromFile(photoFilePath))
            {
                ulong providedPhotoHash = FrameIndexer.CalculateFramePerceptionHashOnly(frame);
                VideoFingerPrintDatabaseMetaTableWrapper metaTable = VideoFingerPrintDatabaseMetaTableLoader.Load(databaseMetaTablePath);
                BKTree <FrameMetricWrapper>           bktree       = ModelMetricUtils.CreateBKTree(metaTable);
                IDictionary <FrameMetricWrapper, int> treeResults  = bktree.Query(
                    new PhotoMetricWrapper
                {
                    Photo = new PhotoFingerPrintWrapper
                    {
                        FilePath = photoFilePath,
                        PHash    = providedPhotoHash,
                    },
                },
                    2
                    );

                foreach (KeyValuePair <FrameMetricWrapper, int> kvp in treeResults.OrderBy(e => e.Value))
                {
                    FrameMetricWrapper frameWrapper = kvp.Key;
                    int distance = kvp.Value;
                    Console.WriteLine(string.Format("Distance {0} for {1} at Frame {2}", distance, frameWrapper.Video.FilePath, frameWrapper.Frame.FrameNumber));
                }
            }
        }
Beispiel #6
0
        private static IEnumerable <string> GetKnownDatabaseEntries(string databaseMetaTablePath)
        {
            if (File.Exists(databaseMetaTablePath) == false)
            {
                return(Enumerable.Empty <string>());
            }

            var knownDatabaseEntries = new HashSet <string>();
            VideoFingerPrintDatabaseMetaTableWrapper metatable = VideoFingerPrintDatabaseMetaTableLoader.Load(databaseMetaTablePath);

            foreach (VideoFingerPrintDatabaseMetaTableEntryWrapper entry in metatable.DatabaseMetaTableEntries)
            {
                VideoFingerPrintDatabaseWrapper database = VideoFingerPrintDatabaseLoader.Load(entry.FileName);
                foreach (VideoFingerPrintWrapper fingerprint in database.VideoFingerPrints)
                {
                    knownDatabaseEntries.Add(fingerprint.FilePath);
                }
            }

            return(knownDatabaseEntries);
        }
        public static VideoFingerPrintDatabaseMetaTableWrapper Coalesce(
            string pathToMetatable
            )
        {
            VideoFingerPrintDatabaseMetaTableWrapper oldMetatable = VideoFingerPrintDatabaseMetaTableLoader.Load(pathToMetatable);
            IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> databasesSelectedForCoalescing = GetDatabasesThatNeedCoalescing(oldMetatable);
            IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> remainingDatabases             = oldMetatable.DatabaseMetaTableEntries.Except(databasesSelectedForCoalescing);
            IEnumerable <IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> > groupedEntries  = DetermineGroups(databasesSelectedForCoalescing);
            IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> coalescedDatabaseGroups        = CoalesceDatabaseGroups(groupedEntries);

            VideoFingerPrintDatabaseMetaTableWrapper newMetaTable = new VideoFingerPrintDatabaseMetaTableWrapper
            {
                DatabaseMetaTableEntries = coalescedDatabaseGroups.Concat(remainingDatabases).ToArray(),
            };

            VideoFingerPrintDatabaseMetaTableSaver.Save(newMetaTable, pathToMetatable);

            // Delete old databases
            DeleteOldDatabases(databasesSelectedForCoalescing);

            return(newMetaTable);
        }