Ejemplo n.º 1
0
        private static VideoFingerPrintWrapper FindMostLikelyVideo(
            PhotoFingerPrintWrapper photo,
            IDictionary <string, ISet <FrameMetricWrapper> > treeResults,
            IDictionary <string, VideoFingerPrintWrapper> nameToVideoMap
            )
        {
            if (treeResults.Count() == 1)
            {
                return(treeResults.First().Value.First().Video);
            }

            using (WritableLockBitImage photoAsLockBitImage = new WritableLockBitImage(Image.FromFile(photo.FilePath)))
            {
                // Filter on grayscale results first
                List <FrameMetricWrapper> filteredOnGrayScaleResults = (from videoFrameResults in treeResults
                                                                        from frameMetricWrapper in videoFrameResults.Value
                                                                        where DistanceCalculator.CalculateHammingDistance(photo.EdgeGrayScaleThumb, frameMetricWrapper.Frame.EdgeGrayScaleThumb) < 2
                                                                        select frameMetricWrapper).ToList();

                if (filteredOnGrayScaleResults.Count == 1)
                {
                    return(filteredOnGrayScaleResults.First().Video);
                }

                double currentBestSSIM = 0.0;
                VideoFingerPrintWrapper currentBestVideo = null;
                foreach (FrameMetricWrapper FrameMetricWrapper in filteredOnGrayScaleResults)
                {
                    // Calculate SSIM
                    using (WritableLockBitImage videoFrame = GetFrameFromVideo(FrameMetricWrapper.Video, FrameMetricWrapper.Frame.FrameNumber))
                    {
                        double possibleBestSSIM = SSIMCalculator.Compute(photoAsLockBitImage, videoFrame);
                        // SSIM must be at least good enough for us to consider
                        if (possibleBestSSIM > currentBestSSIM)
                        {
                            currentBestSSIM  = possibleBestSSIM;
                            currentBestVideo = FrameMetricWrapper.Video;
                        }
                    }
                }

                return(currentBestVideo);
            }
        }
Ejemplo n.º 2
0
        private void RunIndexer()
        {
            foreach (Tuple <Image, string> imageTuple in _fileReader.GetConsumingEnumerable())
            {
                using (imageTuple.Item1)
                {
                    Tuple <ulong, byte[]>   fingerPrintHashTuple = FrameIndexer.IndexFrame(imageTuple.Item1);
                    PhotoFingerPrintWrapper fingerPrint          = new PhotoFingerPrintWrapper
                    {
                        FilePath           = Path.GetFullPath(imageTuple.Item2),
                        PHash              = fingerPrintHashTuple.Item1,
                        EdgeGrayScaleThumb = fingerPrintHashTuple.Item2,
                    };

                    _fingerPrints.Add(fingerPrint);
                    Console.WriteLine("Indexed photo {0}", Path.GetFileName(imageTuple.Item2));
                }
            }
        }
        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);
            }
        }
Ejemplo n.º 4
0
 public int CalculateDistance(PhotoFingerPrintWrapper other)
 {
     return(Frame.CalculateDistance(other));
 }