Пример #1
0
        private IList <ImageFile> FindImages(IImageManager imageManager, IList <ImageFile> fileList)
        {
            //Find the images that resemble each other
            Parallel.ForEach(fileList, file =>
            {
                foreach (var imageFile in fileList)
                {
                    if (file.FullPath != imageFile.FullPath)
                    {
                        lock (file)
                        {
                            var comparisonResult = imageManager.CompareTwoImages(file.Image, imageFile.Image);
                            if (comparisonResult < 10)
                            {
                                file.SimilarImages.Add(imageFile);
                            }
                        }
                    }
                }
            });

            var imagesWithDuplicates = fileList.Where(f => f.SimilarImages.Count > 0).ToList();

            return(imagesWithDuplicates);
        }
Пример #2
0
        public void CompareTwoImagesTest()
        {
            var scaryBearOne = new Bitmap(@"./TestFiles/scarybear.JPG");
            var scaryBearTwo = new Bitmap(@"./TestFiles/scarybear2smallres.jpg");

            Assert.NotNull(scaryBearOne);
            Assert.NotNull(scaryBearTwo);

            var expectedBearResult = 6;

            var bearResult  = _imageManager.CompareTwoImages(scaryBearOne, scaryBearTwo);
            var bearResult2 = _imageManager.CompareTwoImages(scaryBearTwo, scaryBearOne);

            Assert.Equal(expectedBearResult, bearResult);
            Assert.Equal(expectedBearResult, bearResult2);


            var elephantOne = new Bitmap(@"./TestFiles/elephant1.jpg");
            var elephantTwo = new Bitmap(@"./TestFiles/elephant2.jpg");

            Assert.NotNull(elephantOne);
            Assert.NotNull(elephantTwo);

            var expectedElephantResult = 0;

            var elephantResult = _imageManager.CompareTwoImages(elephantOne, elephantTwo);

            Assert.Equal(expectedElephantResult, elephantResult);


            var cat = new Bitmap(@"./TestFiles/mew.jpg");

            Assert.NotNull(cat);

            var expectedCatElephantResult = 98;
            var catElephantResult         = _imageManager.CompareTwoImages(cat, elephantOne);

            Assert.Equal(expectedCatElephantResult, catElephantResult);
        }