Exemple #1
0
        virtual protected void CompareImages(string FileName1, string FileName2)
        {
            var Hash1 = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(FileName1)), Levels);
            var Hash2 = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(FileName2)), Levels);

            Console.Write("{0:0.000000}", SimilarImage.CompareHashes(Hash1, Hash2));
        }
Exemple #2
0
        public List <ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List <ImageRecord> rtnImageList = new List <ImageRecord>();

            string queryImageCompressHash;

            using (Bitmap bmp = new Bitmap(System.Drawing.Image.FromFile(queryImagePath)))
            {
                queryImageCompressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
            }
            BinaryAlgoRepository <List <PHashImageRecord> > repo = new BinaryAlgoRepository <List <PHashImageRecord> >();
            List <PHashImageRecord> AllImage = repo.Load();

            foreach (var imgInfo in AllImage)
            {
                var dist = SimilarImage.CompareHashes(queryImageCompressHash, imgInfo.CompressHash);
                if (dist > 0.8)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }

            rtnImageList = rtnImageList.OrderByDescending(x => x.Distance).ToList();

            return(rtnImageList);
        }
Exemple #3
0
        public void TestMethod1()
        {
            var Path    = "../../../../Samples";
            var Hash1_a = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(Path + "/test1_a.png")));
            var Hash1_b = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(Path + "/test1_b.png")));
            var Hash1_c = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(Path + "/test1_c.png")));

            var Hash2 = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(Path + "/test2.png")));

            var Hash3_a = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(Path + "/test3_a.jpg")));
            var Hash3_b = SimilarImage.GetCompressedImageHashAsString(new Bitmap(Image.FromFile(Path + "/test3_b.jpg")));

            Assert.IsTrue(SimilarImage.CompareHashesBool(Hash1_a, Hash1_b));
            Assert.IsTrue(SimilarImage.CompareHashesBool(Hash1_a, Hash1_c));

            Assert.IsFalse(SimilarImage.CompareHashesBool(Hash1_a, Hash2));
            Assert.IsFalse(SimilarImage.CompareHashesBool(Hash1_a, Hash3_a));

            Assert.IsTrue(SimilarImage.CompareHashesBool(Hash3_a, Hash3_b));
            Assert.IsFalse(SimilarImage.CompareHashesBool(Hash3_a, Hash2));

            Assert.AreEqual(SimilarImage.CompareHashes(Hash1_a, Hash1_b), SimilarImage.CompareHashes(Hash1_b, Hash1_a));
        }
Exemple #4
0
 virtual protected void CompareHashes(string Hash1, string Hash2)
 {
     Console.Write("{0:0.000000}", SimilarImage.CompareHashes(Hash1, Hash2));
 }