示例#1
0
 public void CreateAndDispose()
 {
     using (var model = PHash.Create())
     {
         GC.KeepAlive(model);
     }
 }
示例#2
0
 public void CompareSameImage()
 {
     using (var model = PHash.Create())
         using (var img1 = Image("lenna.png", ImreadModes.GrayScale))
         {
             double hash = model.Compare(img1, img1);
             Assert.Equal(0, hash, 6);
         }
 }
示例#3
0
 public void CompareDifferentImage()
 {
     using (var model = PHash.Create())
         using (var img1 = Image("lenna.png", ImreadModes.GrayScale))
             using (var img2 = Image("building.jpg", ImreadModes.GrayScale))
             {
                 var size = new Size(256, 256);
                 using (var scaledImg1 = img1.Resize(size))
                     using (var scaledImg2 = img2.Resize(size))
                     {
                         double hash = model.Compare(scaledImg1, scaledImg2);
                         Assert.Equal(264411, hash, 6);
                     }
             }
 }
示例#4
0
        public void Compute()
        {
            using (var model = PHash.Create())
                using (var img = Image("lenna.png"))
                    using (var hash = new MatOfByte())
                    {
                        model.Compute(img, hash);
                        Assert.Equal(1, hash.Rows);
                        Assert.Equal(8, hash.Cols);
                        Assert.Equal(MatType.CV_8UC1, hash.Type());

                        var hashArray = hash.ToArray();
                        Assert.Equal(152, hashArray[0]);
                        Assert.Equal(99, hashArray[1]);
                        Assert.Equal(42, hashArray[2]);
                        Assert.Equal(180, hashArray[3]);
                        Assert.Equal(206, hashArray[4]);
                        Assert.Equal(197, hashArray[5]);
                        Assert.Equal(97, hashArray[6]);
                        Assert.Equal(25, hashArray[7]);
                    }
        }