Ejemplo n.º 1
0
        public void MatchTest2()
        {
            var imgOld = Accord.Imaging.Image.Clone(Resources.old);
            var imgNew = Accord.Imaging.Image.Clone(Resources._new);
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(imgOld).ToArray();
            var keyPoints2 = freak.ProcessImage(imgNew).ToArray();

            var matcher = new KNearestNeighborMatching <byte[]>(5, new Hamming());

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }
        }
        public void MatchTest2()
        {
            var imgOld = Accord.Imaging.Image.Clone(Properties.Resources.old);
            var imgNew = Accord.Imaging.Image.Clone(Properties.Resources._new); 
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(imgOld).ToArray();
            var keyPoints2 = freak.ProcessImage(imgNew).ToArray();

            var matcher = new KNearestNeighborMatching<byte[]>(5, new Hamming());

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }

        }
        public void MatchTest3()
        {
            FastCornersDetector fast = new FastCornersDetector(threshold: 10);

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var keyPoints1 = freak.ProcessImage(Properties.Resources.old).ToArray();
            var keyPoints2 = freak.ProcessImage(Properties.Resources.flower01).ToArray();

            var matcher = new KNearestNeighborMatching <byte[]>(5, Distance.BitwiseHamming);

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(138, matches[0].Length);
                Assert.AreEqual(138, matches[1].Length);
                Assert.AreEqual(532, matches[0][0].X);
                Assert.AreEqual(159, matches[0][0].Y);
                Assert.AreEqual(keyPoints2[0].ToIntPoint(), matches[1][0]);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(138, matches[0].Length);
                Assert.AreEqual(138, matches[1].Length);
                Assert.AreEqual(keyPoints2[0].ToIntPoint(), matches[0][0]);
                Assert.AreEqual(532, matches[1][0].X);
                Assert.AreEqual(159, matches[1][0].Y);
            }
        }
Ejemplo n.º 4
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                Bitmap img1 = ImageL;
                Bitmap img2 = ImageR;
                FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();
                FastRetinaKeypoint[]       keyPoints1;
                FastRetinaKeypoint[]       keyPoints2;
                keyPoints1 = freak.ProcessImage(img1).ToArray();
                keyPoints2 = freak.ProcessImage(img2).ToArray();

                var          matcher = new KNearestNeighborMatching <byte[]>(5, new Hamming());
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);

                // Get the two sets of points
                correlationPoints1 = matches[0];
                correlationPoints2 = matches[1];

                RansacHomographyEstimator ransac = new RansacHomographyEstimator(0.001, 0.99);
                homography = ransac.Estimate(correlationPoints1, correlationPoints2);

                // Plot RANSAC results against correlation results
                //IntPoint[] inliers1 = correlationPoints1.Submatrix(ransac.Inliers);
                //IntPoint[] inliers2 = correlationPoints2.Submatrix(ransac.Inliers);

                Blend blend = new Blend(homography, img1);
                m_stitpic_box.Image = blend.Apply(img2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        public void ExampleTest()
        {
            Bitmap lena = Resources.lena512;

            // The freak detector can be used with any other corners detection
            // algorithm. The default corners detection method used is the FAST
            // corners detection. So, let's start creating this detector first:
            //
            var detector = new FastCornersDetector(60);

            // Now that we have a corners detector, we can pass it to the FREAK
            // feature extraction algorithm. Please note that if we leave this
            // parameter empty, FAST will be used by default.
            //
            var freak = new FastRetinaKeypointDetector(detector);

            // Now, all we have to do is to process our image:
            List<FastRetinaKeypoint> points = freak.ProcessImage(lena);

            // Afterwards, we should obtain 83 feature points. We can inspect
            // the feature points visually using the FeaturesMarker class as
            //
            FeaturesMarker marker = new FeaturesMarker(points, scale: 20);
            
            // And showing it on screen with
            // ImageBox.Show(marker.Apply(lena));

            // We can also inspect the feature vectors (descriptors) associated
            // with each feature point. In order to get a descriptor vector for
            // any given point, we can use
            //
            byte[] feature = points[42].Descriptor;
            
            // By default, feature vectors will have 64 bytes in length. We can also
            // display those vectors in more readable formats such as HEX or base64
            //
            string hex = points[42].ToHex();
            string b64 = points[42].ToBase64();

            // The above base64 result should be:
            //
            //  "3W8M/ev///ffbr/+v3f34vz//7X+f0609v//+++/1+jfq/e83/X5/+6ft3//b4uaPZf7ePb3n/P93/rIbZlf+g=="
            //

            Assert.AreEqual(83, points.Count);
            Assert.AreEqual(64, feature.Length);
            Assert.AreEqual("3W8M/ev///ffbr/+v3f34vz//7X+f0609v//+++/1+jfq/e83/X5/+6ft3//b4uaPZf7ePb3n/P93/rIbZlf+g==", b64);
        }
        public void ExampleTest()
        {
            Bitmap lena = Accord.Imaging.Image.Clone(Resources.lena512);

            // The freak detector can be used with any other corners detection
            // algorithm. The default corners detection method used is the FAST
            // corners detection. So, let's start creating this detector first:
            //
            var detector = new FastCornersDetector(60);

            // Now that we have a corners detector, we can pass it to the FREAK
            // feature extraction algorithm. Please note that if we leave this
            // parameter empty, FAST will be used by default.
            //
            var freak = new FastRetinaKeypointDetector(detector);

            // Now, all we have to do is to process our image:
            List <FastRetinaKeypoint> points = freak.ProcessImage(lena);

            // Afterwards, we should obtain 83 feature points. We can inspect
            // the feature points visually using the FeaturesMarker class as
            //
            FeaturesMarker marker = new FeaturesMarker(points, scale: 20);

            // And showing it on screen with
            // ImageBox.Show(marker.Apply(lena));

            // We can also inspect the feature vectors (descriptors) associated
            // with each feature point. In order to get a descriptor vector for
            // any given point, we can use
            //
            byte[] feature = points[42].Descriptor;

            // By default, feature vectors will have 64 bytes in length. We can also
            // display those vectors in more readable formats such as HEX or base64
            //
            string hex = points[42].ToHex();
            string b64 = points[42].ToBase64();

            // The above base64 result should be:
            //
            //  "3W8M/ev///ffbr/+v3f34vz//7X+f0609v//+++/1+jfq/e83/X5/+6ft3//b4uaPZf7ePb3n/P93/rIbZlf+g=="
            //

            Assert.AreEqual(83, points.Count);
            Assert.AreEqual(64, feature.Length);
            Assert.AreEqual("3W8M/ev///ffbr/+v3f34vz//7X+f0609v//+++/1+jfq/e83/X5/+6ft3//b4uaPZf7ePb3n/P93/rIbZlf+g==", b64);
        }
Ejemplo n.º 7
0
        private void btnFreak_Click(object sender, EventArgs e)
        {
            // Step 1: Detect feature points using FREAK Features Detector
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            keyPoints1 = freak.ProcessImage(img1).ToArray();
            keyPoints2 = freak.ProcessImage(img2).ToArray();

            // Show the marked points in the original images
            Bitmap img1mark = new PointsMarker(keyPoints1).Apply(img1);
            Bitmap img2mark = new PointsMarker(keyPoints2).Apply(img2);

            // Concatenate the two images together in a single image (just to show on screen)
            Concatenate concatenate = new Concatenate(img1mark);
            pictureBox.Image = concatenate.Apply(img2mark);
        }
Ejemplo n.º 8
0
    protected void drawFreakFeatures(List <Bitmap> imgs)
    {
        List <FastRetinaKeypoint[]> freakPoints = new List <FastRetinaKeypoint[]>();
        //Calculate all the FREAK Points
        FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

        foreach (Bitmap img in imgs)
        {
            freakPoints.Add(freak.ProcessImage(img).ToArray());
        }

        //Draw & Show all the harris points
        for (int i = 0; i < imgs.Count; i++)
        {
            showImage(new PointsMarker(freakPoints[i]).Apply(imgs[i]));
        }
    }
Ejemplo n.º 9
0
        private void btnFreak_Click(object sender, EventArgs e)
        {
            // Step 1: Detect feature points using FREAK Features Detector
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            keyPoints1 = freak.ProcessImage(img1).ToArray();
            keyPoints2 = freak.ProcessImage(img2).ToArray();

            // Show the marked points in the original images
            Bitmap img1mark = new PointsMarker(keyPoints1.Apply(p => (IntPoint)p)).Apply(img1);
            Bitmap img2mark = new PointsMarker(keyPoints2.Apply(p => (IntPoint)p)).Apply(img2);

            // Concatenate the two images together in a single image (just to show on screen)
            Concatenate concatenate = new Concatenate(img1mark);

            pictureBox.Image = concatenate.Apply(img2mark);
        }
Ejemplo n.º 10
0
        private void btnFreak_Click(object sender, EventArgs e)
        {
            // Step 1: Detect feature points using FREAK Features Detector
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            keyPoints1 = freak.Transform(img1);
            keyPoints2 = freak.Transform(img2);

            // Show the marked points in the original images
            // TODO: The following construct can be simplified
            Bitmap img1mark = new PointsMarker(keyPoints1.Select(x => (IFeaturePoint)x).ToList()).Apply(img1);
            Bitmap img2mark = new PointsMarker(keyPoints2.Select(x => (IFeaturePoint)x).ToList()).Apply(img2);

            // Concatenate the two images together in a single image (just to show on screen)
            Concatenate concatenate = new Concatenate(img1mark);

            pictureBox.Image = concatenate.Apply(img2mark);
        }
        public void MatchTest()
        {
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(Properties.Resources.image1).ToArray();
            var keyPoints2 = freak.ProcessImage(Properties.Resources.image2).ToArray();

            bool thrown = false;

            try
            {
                var          matcher = new KNearestNeighborMatching <byte[]>(5, Distance.BitwiseHamming);
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
            }
            catch (ArgumentException)
            {
                thrown = true;
            }

            Assert.IsTrue(thrown);
        }
        public void MatchTest()
        {
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(Properties.Resources.image1).ToArray();
            var keyPoints2 = freak.ProcessImage(Properties.Resources.image2).ToArray();

            bool thrown = false;

            try
            {
                var matcher = new KNearestNeighborMatching<byte[]>(5, Distance.BitwiseHamming);
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
            }
            catch (ArgumentException)
            {
                thrown = true;
            }

            Assert.IsTrue(thrown);
        }
Ejemplo n.º 13
0
        public void SerializeTest2()
        {
            var images = BagOfVisualWordsTest.images.DeepClone();

            Accord.Math.Tools.SetupGenerator(0);

            FastCornersDetector fast = new FastCornersDetector();

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var kmodes = new KModes <byte>(5, Distance.BitwiseHamming);

            var bow = new BagOfVisualWords <FastRetinaKeypoint, byte[]>(freak, kmodes);

            bow.Compute(images);


            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = bow.GetFeatureVector(images[i]);
            }

            MemoryStream    stream = new MemoryStream();
            BinaryFormatter fmt    = new BinaryFormatter();

            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords <FastRetinaKeypoint, byte[]>)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }


            Assert.IsTrue(expected.IsEqual(actual));
        }
Ejemplo n.º 14
0
        public void SerializeTest2()
        {
            var images = GetImages();

            Accord.Math.Random.Generator.Seed = 0;

            FastCornersDetector fast = new FastCornersDetector();

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var kmodes = new KModes <byte>(5, new Hamming());

            kmodes.ParallelOptions.MaxDegreeOfParallelism = 1;

            var bow = new BagOfVisualWords <FastRetinaKeypoint, byte[]>(freak, kmodes);

            bow.Compute(images);

            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = bow.GetFeatureVector(images[i]);
            }

            MemoryStream    stream = new MemoryStream();
            BinaryFormatter fmt    = new BinaryFormatter();

            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords <FastRetinaKeypoint, byte[]>)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            Assert.IsTrue(expected.IsEqual(actual));
        }
Ejemplo n.º 15
0
    protected void freakRansacBlend(List <Bitmap> imgs)
    {
        MatrixH homography;

        List <FastRetinaKeypoint[]> freakPoints = new List <FastRetinaKeypoint[]>();
        //Calculate all the FREAK Points
        FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

        foreach (Bitmap img in imgs)
        {
            freakPoints.Add(freak.ProcessImage(img).ToArray());
        }

        //Map them and draw them!
        Bitmap final = imgs[0];

        for (int i = 1; i < imgs.Count; i++)
        {
            FastRetinaKeypoint[] freakFinal = freak.ProcessImage(final).ToArray();

            KNearestNeighborMatching matcher = new KNearestNeighborMatching(500);
            matcher.Threshold = 0.005;
            IntPoint[][] matches = matcher.Match(freakFinal, freakPoints[i]);

            RansacHomographyEstimator ransac = new RansacHomographyEstimator(0.015, 1);
            homography = ransac.Estimate(matches[0], matches[1]);

            Blend blend = new Blend(homography, final);
            blend.Gradient = true;
            final          = blend.Apply(imgs[i]);
        }

        //Smooth/Sharpen if I wanted to
        AForge.Imaging.Filters.Sharpen filter = new AForge.Imaging.Filters.Sharpen();
        //AForge.Imaging.Filters.Gaussian filter = new AForge.Imaging.Filters.Guassian(5);
        //filter.ApplyInPlace(final);

        showImage(final);
    }
Ejemplo n.º 16
0
    protected void drawFreakFeaturesCorrelations(List <Bitmap> imgs)
    {
        List <FastRetinaKeypoint[]> freakPoints = new List <FastRetinaKeypoint[]>();
        //Calculate all the FREAK Points
        FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

        foreach (Bitmap img in imgs)
        {
            freakPoints.Add(freak.ProcessImage(img).ToArray());
        }

        //Map them and draw them!
        Bitmap img2 = imgs[0];

        for (int i = 0; i < imgs.Count - 1; i++)
        {
            KNearestNeighborMatching matcher = new KNearestNeighborMatching(200);
            matcher.Threshold = 0.015;
            IntPoint[][] matches = matcher.Match(freakPoints[i], freakPoints[i + 1]);

            Concatenate concat = new Concatenate(img2);
            Bitmap      img3   = concat.Apply(imgs[i + 1]);

            Color color = Color.White;
            if (i % 3 == 1)
            {
                color = Color.OrangeRed;
            }
            if (i % 3 == 2)
            {
                color = Color.Blue;
            }
            PairsMarker pairs = new PairsMarker(matches[0].Apply(p => new IntPoint(p.X + img2.Width - imgs[0].Width, p.Y)), matches[1].Apply(p => new IntPoint(p.X + img2.Width, p.Y)), color);
            img2 = pairs.Apply(img3);
        }

        showImage(img2);
    }
Ejemplo n.º 17
0
        public void MatchTest()
        {
            var image1 = Accord.Imaging.Image.Clone(Resources.image1);
            var image2 = Accord.Imaging.Image.Clone(Resources.image2);
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(image1).ToArray();
            var keyPoints2 = freak.ProcessImage(image2).ToArray();

            bool thrown = false;

            try
            {
                var          matcher = new KNearestNeighborMatching <byte[]>(5, new Hamming());
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
            }
            catch (ArgumentException)
            {
                thrown = true;
            }

            Assert.IsTrue(thrown);
        }
        public void MatchTest2()
        {
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(Properties.Resources.old).ToArray();
            var keyPoints2 = freak.ProcessImage(Properties.Resources._new).ToArray();

            var matcher = new KNearestNeighborMatching <byte[]>(5, Distance.BitwiseHamming);

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }
        }
        public void MatchTest2()
        {
            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector();

            var keyPoints1 = freak.ProcessImage(Properties.Resources.old).ToArray();
            var keyPoints2 = freak.ProcessImage(Properties.Resources._new).ToArray();

            var matcher = new KNearestNeighborMatching<byte[]>(5, Distance.BitwiseHamming);

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(1, matches[0].Length);
                Assert.AreEqual(1, matches[1].Length);
            }

        }
Ejemplo n.º 20
0
        public void MatchTest3()
        {
            Accord.Math.Random.Generator.Seed = 0;

            var old      = Accord.Imaging.Image.Clone(Resources.old);
            var flower01 = Accord.Imaging.Image.Clone(Resources.flower01);

            FastCornersDetector fast = new FastCornersDetector(threshold: 10);

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var keyPoints1 = freak.ProcessImage(old).ToArray();
            var keyPoints2 = freak.ProcessImage(flower01).ToArray();

            var matcher = new KNearestNeighborMatching <byte[]>(5, new Hamming());

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(143, matches[0].Length);
                Assert.AreEqual(143, matches[1].Length);
                Assert.AreEqual(532, matches[0][0].X);
                Assert.AreEqual(159, matches[0][0].Y);
                Assert.AreEqual(keyPoints2[0].ToIntPoint(), matches[1][0]);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(143, matches[0].Length);
                Assert.AreEqual(143, matches[1].Length);
                Assert.AreEqual(keyPoints2[0].ToIntPoint(), matches[0][0]);
                Assert.AreEqual(532, matches[1][0].X);
                Assert.AreEqual(159, matches[1][0].Y);
            }
        }
        public void SerializeTest2()
        {
            Accord.Math.Tools.SetupGenerator(0);

            FastCornersDetector fast = new FastCornersDetector();

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var kmodes = new KModes<byte[]>(5, Distance.BitwiseHamming);

            var bow = new BagOfVisualWords<FastRetinaKeypoint, byte[]>(freak, kmodes);

            bow.Compute(images);



            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
                expected[i] = bow.GetFeatureVector(images[i]);

            MemoryStream stream = new MemoryStream();
            BinaryFormatter fmt = new BinaryFormatter();
            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords<FastRetinaKeypoint, byte[]>)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
                actual[i] = bow.GetFeatureVector(images[i]);


            Assert.IsTrue(expected.IsEqual(actual));
        }
        public void ProcessImageTest()
        {
            Bitmap lena = Properties.Resources.lena512;

            FastRetinaKeypointDetector target = new FastRetinaKeypointDetector();

            List<FastRetinaKeypoint> actual = target.ProcessImage(lena);

            string code;
            Assert.AreEqual(1283, actual.Count);

            int i = 0;
            Assert.AreEqual(223, actual[i].X);
            Assert.AreEqual(45, actual[i].Y);
            Assert.AreEqual(80.122163710144434, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("00101100101000101100000010111000110111111010111011110000011011110111111111101001011000111111010110100110101001000010100000001100100000111110110100000010100010010000100000110000100010110000000101110001100100101100011010111101100100110101111110000100010100111101100001010101110010000001100111111010100001111000111001101000011101111011110111001101111010101101001111110101010100000100100100101100101010011010011000000000001010000110101010011000111001111011111101110101110011100001001010110010100100001000101001010011", code);
            code = actual[i].ToHex();
            Assert.AreEqual("3445031dfb750ff6fe97c6af65251430c1b74091100cd1808e4963bdc9fa21ca1baa13985fe17116eebdb357cbaf0a9234956500145619e7fdae73484d0951ca", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("NEUDHft1D/b+l8avZSUUMMG3QJEQDNGAjkljvcn6IcobqhOYX+FxFu69s1fLrwqSNJVlABRWGef9rnNITQlRyg==", code);

            i = 124;
            Assert.AreEqual(141.0, actual[i].X);
            Assert.AreEqual(184.0, actual[i].Y);
            Assert.AreEqual(158.74949449286677, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("11111000010001010000011000000010000100100010010101000010100000011110101010110111001110010110111110010101100001000100010100001000110010000001010000010000000001010011010110000010101110110000001000010000100000010101011010111011110000001011101110001011100001110010000001000000001011000010100010001001100001101000010100001000000001001010110100000000001010011101001010000111011010011000110010000100110000100010011001010000001010010110001000010000111000011000000000100100110000100001001000010010100100000000100001000001", code);
            code = actual[i].ToHex();
            Assert.AreEqual("1fa2604048a4428157ed9cf6a921a210132808a0ac41dd4008816add03ddd1e1040234149161a11020b500944be196312143640a944608870124434848091082", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("H6JgQEikQoFX7Zz2qSGiEBMoCKCsQd1ACIFq3QPd0eEEAjQUkWGhECC1AJRL4ZYxIUNkCpRGCIcBJENISAkQgg==", code);

            i = 763;
            Assert.AreEqual(104, actual[i].X);
            Assert.AreEqual(332, actual[i].Y);
            Assert.AreEqual(-174.28940686250036, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("01010001111011001100011000010110101011111010010001000101001111110111111101101101111000101101010111010110111010001110001011011100111000010000010111100000010010010101010001010001110100010101111011000001101100111001001100001000101100010111011110111100111101110100011000100101001010010011010000111110000100000000000011001000000011111011010011011001001010011101010011111101001001010111000001010100011011110111010000010101100000010110110101111100101111111000100011111001100011100000110011011011100000001010100101011101", code);
            code = actual[i].ToHex();
            Assert.AreEqual("8a376368f525a2fcfeb647ab6b17473b87a007922a8a8b7a83cdc9108dee3def62a4942c7c080013f02d9b942bbfa40e2af62ea881b63efd119f7130db0195ba", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("ijdjaPUlovz+tkeraxdHO4egB5Iqiot6g83JEI3uPe9ipJQsfAgAE/Atm5Qrv6QOKvYuqIG2Pv0Rn3Ew2wGVug==", code);

            i = 1042;
            Assert.AreEqual(116, actual[i].X);
            Assert.AreEqual(410, actual[i].Y);
            Assert.AreEqual(-86.11209043916692, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("11110111010011000010101001011011010101100111010011011101001111010110001010110000111001010111101011001011001001101101100011011011110111110000010111111000000000010001001000010110101010010001100011011110101000100101100010101100000100111011101100010110001000111000100001110100001000110001110011111011000001100000111001001000011111111011010101001101110000010101001110111101011100001100110110000100111010100010000001000000011110000110111010011000111100111011111110110101110011100000001001110010100100001000101001110011", code);
            code = actual[i].ToHex();
            Assert.AreEqual("ef3254da6a2ebbbc460da75ed3641bdbfba01f80486895187b451a35c8dd68c4112ec438df607012feadb283cabd0eb3215704021e7619cffdad73404e0951ce", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("7zJU2mouu7xGDade02Qb2/ugH4BIaJUYe0UaNcjdaMQRLsQ432BwEv6tsoPKvQ6zIVcEAh52Gc/9rXNATglRzg==", code);

            i = 1282;
            Assert.AreEqual(425.0, actual[i].X);
            Assert.AreEqual(488.0, actual[i].Y);
            Assert.AreEqual(-70.722526916337571, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("10111011111111011101111000011111111101110111111011111111111111111111111111111011011110111111111111111111011011101001111101101110111101111111101111111110111011101111111010110011100100111110101101111111111110111111111110111111111111111111011011101101110111111111111010110101110111000001010101111111100111011000111111110111011100111111111111111101111110101111111111110111010101000111011100111111101011011011111100011011111011111111101111111001111011111011111111110111111111110001001110111110100110101111111001010111", code);
            code = actual[i].ToHex();
            Assert.AreEqual("ddbf7bf8ef7effffffdfdeffff76f976efdf7f777fcdc9d7fedffffdff6fb7fb7fad3ba8feb9f1efceffbf5fffef2aeefcb5fdd8f7df9ff7fdefffc87d597fea", code);
        }
        public void ProcessImageTest2()
        {
            Bitmap lena = Properties.Resources.lena512;

            FastRetinaKeypointDetector target = new FastRetinaKeypointDetector();
            target.ComputeDescriptors = FastRetinaKeypointDescriptorType.Extended;

            List<FastRetinaKeypoint> actual = target.ProcessImage(lena);

            string code;
            Assert.AreEqual(1283, actual.Count);

            int i = 0;
            Assert.AreEqual(223, actual[i].X);
            Assert.AreEqual(45, actual[i].Y);
            Assert.AreEqual(80.122163710144434, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000000000011110111100011100000000000000100010011100111111111111111111111111100111100111100000010001100000000100010000000000000000000000011111111110011110111111111100111100011100111100011100000000000000000000000000000000000000000000011100111000011100011111111111110111111111111111111111100111111111100111100111100111100111100001110001100001110001100000000000000000000000000000000000100010000000100011000001011110011110001110011110001111111111111100111111111100111110011100111100011100111100011100000010001000000010001100000100000000100010000000100011000001000000011100111100011100111100011100011111111111110011111111110011111111111111111111100111111111100111110111100111111111100111100111100111110111100001110001100001110001100001110001100000001100011000011100011000001100011000000011100011000011100011000011100011000011011111111110011110011110011111011110001110111100111100011100111100011100111100011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("00788f030091f3ffff9fe7811820020000fee7fdcfe33c0e0000000000cee1f8fffeff7ffee7799e876338060000004004c4a0e7711eff3ffff3398ff3381001310810013108388ff338fe3ffff3fffff99feff99fe7f91e8ee1188e0163380663c0311cc331ec7f9ee77bdcf3388ff338000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("AHiPAwCR8///n+eBGCACAAD+5/3P4zwOAAAAAADO4fj//v9//ud5nodjOAYAAABABMSg53Ee/z//8zmP8zgQATEIEAExCDiP8zj+P//z///5n+/5n+f5Ho7hGI4BYzgGY8AxHMMx7H+e53vc8ziP8zgAAAAAAAAAAAAAAAAAAAA=", code);

            i = 124;
            Assert.AreEqual(141.0, actual[i].X);
            Assert.AreEqual(184.0, actual[i].Y);
            Assert.AreEqual(158.74949449286677, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000000001001110111110011100000110000000000000011100011001111011110011100111100011100111100001110001110000001000001000000011100011000001001110001110000110011100011100011110011100011100001100001110001110000110000001100011000001000000011100011100001100111001110001100000100000100001100001000001000000000001100001000001000000001001110001100000100000101110001100011000001000001001100011100011100001100111011111001110001100000100000100110100001000001000000000000000000000001000001000000000000000000001001110001100000100000100110100110011100011000001100001011111011110011100011100001110111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000110001100000100000000110000110001110001100011000001000001001100001100011110011100011100001110111111111111111011111001110001100000100000100110100110001111100001000001000000000000000000000000011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("00729f83018063de731ee7e13810041c831c87398ee7380cc761600c028ec39c6310842108802108906310748c4190711ce63ec720c842100000100400801c8320cb1c83a1ef390ef7ff07000000000000000000000000408c4180611c63106418cf71b8ffbfcf3108b28c0f4100000007000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("AHKfgwGAY95zHufhOBAEHIMchzmO5zgMx2FgDAKOw5xjEIQhCIAhCJBjEHSMQZBxHOY+xyDIQhAAABAEAIAcgyDLHIOh7zkO9/8HAAAAAAAAAAAAAAAAQIxBgGEcYxBkGM9xuP+/zzEIsowPQQAAAAcAAAAAAAAAAAAAAAAAAAA=", code);

            i = 763;
            Assert.AreEqual(104, actual[i].X);
            Assert.AreEqual(332, actual[i].Y);
            Assert.AreEqual(-174.28940686250036, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000010000000010010110010110000011000000000000000000001000011000110000110001100000110001111011111111111110000000000000000000000000000000011111111111111110000000000000001100000000000000000100000011000110100110110000000000000000000000000000001000001101101011111111111110110111110000000000000000100001000000000000000000000000000111111111111111111111111110000000000000000000001000100000000000000000000001000101111111111111111111111111110110000000000000000000001000100000111111111111111111111111101101111111111111111111111111111111110000000000000001100101001101101001111111111111111111111111101101101111111111111111111111111111111111110011111111111101101111101101101001000000000000000000100001001101101000000111111111111111111111111111111111111110010110111111101101111101101101001000100000110001100001101101101101101001000100111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("20409a0603004018c3188cf7ff01000000feff01000300088c6503000000c1d6ffb70f0010020000e0ffff7f000010010080e8ffffff06000011fcffffb7ffffffff0080295bfeffffb7fdffffff3fff6fdf960000846c81ffffffff9ff6b76f4b0463d8b625f2ffffffffffffffffff3f000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("IECaBgMAQBjDGIz3/wEAAAD+/wEAAwAIjGUDAAAAwdb/tw8AEAIAAOD//38AABABAIDo////BgAAEfz//7f/////AIApW/7//7f9////P/9v35YAAIRsgf////+f9rdvSwRj2LYl8v///////////z8AAAAAAAAAAAAAAAAAAAA=", code);

            i = 1042;
            Assert.AreEqual(116, actual[i].X);
            Assert.AreEqual(410, actual[i].Y);
            Assert.AreEqual(-86.11209043916692, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000000001001111111110011100000000000001100010011100111000110001000001100010000011110111111000110001000000000000000000000001100010000011001110011101101110011110111111011110000000000000001000000100001000000100010000000000000000000000001100010001011100111000110001000001100011100011100111011011100111110011110111111011110111111000000000000000100000100000000000000000000000000000000001100010011011100111110011001111011111101111011111111111111111111111111111111111111110001100010011011100111110011000000000000000000100010100001100000000000000000001000001000001000000011110111111111111111111111110111001111011111101111111111111111011101111111111111111111111111111110111111111111111111111111111111111110111111000110001000001100011101001100001100000000000000000001000001000001000000000000011100111011011100111111011100111000011111111011111111111111111111111011111001111111110111111111111111111111110111110011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("00f29f038091738c6004efc708000018c19cdb79bf07000442200200008ce81c2318c7b99dcffbbd1f0010040000006064e733eff7feffffffff31b2f3190080280c0080200878ffff7fe7fdfeffddffffffefffffffff7e8c605c860100100401c0b99ddf39fcfbfffffbfcf7fffff739000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("APKfA4CRc4xgBO/HCAAAGMGc23m/BwAEQiACAACM6BwjGMe5nc/7vR8AEAQAAABgZOcz7/f+/////zGy8xkAgCgMAIAgCHj//3/n/f7/3f///+//////foxgXIYBABAEAcC5nd85/Pv///v89///9zkAAAAAAAAAAAAAAAAAAAA=", code);

            i = 1282;
            Assert.AreEqual(425.0, actual[i].X);
            Assert.AreEqual(488.0, actual[i].Y);
            Assert.AreEqual(-70.722526916337571, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000110000000000111110000010011011010110110110000000000011111011111111111111110111110111100000011010010000111110111100010110110110100010011111011110011111111111111111111110111110111100011100011111011110001110000111110111100011100010111110111100111110111111111111111111111011111111111111111111111111111111111111110111110111100011111011110011111011110000111110111100111110111100010111110111100111110111100011111111111111011111011110001111111111111111111111111110111110111111111110111110111100011100011111011111011111011110001110000111111111110111110111100011100010111111111110111110111100011100111111111111111111111111111011111011111111111111111111111111111111111111111111111111111111111111110111110111100111111111111011111011110001110011110000111111111110111110111100011100011000001111111111110111110111100011100111100011111111111111111111111111011111011110011111111111111111111111111110111110111100111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("30001f646b1b00dfffbfef81257c8fb645bee7fffff73d8eef71f81e47dff3fdff7fffffffffffbec7f77c0fdff33dfa9eeff1fffb1efffffff7fddff738beef7b1cfeef7b1cfddff738fffffff7fdfffffffffffffffb9efff73dcec3ff7d8f63f0ffbec779fcffffef7bfeffffdff73c000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("MAAfZGsbAN//v++BJXyPtkW+5///9z2O73H4Hkff8/3/f///////vsf3fA/f8z36nu/x//se////9/3f9zi+73sc/u97HP3f9zj////3/f/////////7nv/3Pc7D/32PY/D/vsd5/P//73v+///f9zwAAAAAAAAAAAAAAAAAAAA=", code);
        }
        public void MatchTest3()
        {
            FastCornersDetector fast = new FastCornersDetector(threshold: 10);

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var keyPoints1 = freak.ProcessImage(Properties.Resources.old).ToArray();
            var keyPoints2 = freak.ProcessImage(Properties.Resources.flower01).ToArray();

            var matcher = new KNearestNeighborMatching<byte[]>(5, Distance.BitwiseHamming);

            { // direct
                IntPoint[][] matches = matcher.Match(keyPoints1, keyPoints2);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(143, matches[0].Length);
                Assert.AreEqual(143, matches[1].Length);
                Assert.AreEqual(532, matches[0][0].X);
                Assert.AreEqual(159, matches[0][0].Y);
                Assert.AreEqual(keyPoints2[0].ToIntPoint(), matches[1][0]);
            }

            { // reverse
                IntPoint[][] matches = matcher.Match(keyPoints2, keyPoints1);
                Assert.AreEqual(2, matches.Length);
                Assert.AreEqual(143, matches[0].Length);
                Assert.AreEqual(143, matches[1].Length);
                Assert.AreEqual(keyPoints2[0].ToIntPoint(), matches[0][0]);
                Assert.AreEqual(532, matches[1][0].X);
                Assert.AreEqual(159, matches[1][0].Y);
            }

        }
        /// <summary>
        /// This methods only for admin, and this recompute bagOfContourFragments and svm
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCompute_Click(object sender, EventArgs e)
        {
            //Accord.Math.Random.Generator.Seed = 1;

            DirectoryInfo path = new DirectoryInfo(Path.Combine(Application.StartupPath, "Resources/Res"));

            ///Create dictionary for train images
            originalTrainImages = new Dictionary <int, Bitmap>();

            int j = 0;

            int k = 0;

            foreach (DirectoryInfo classFolder in path.EnumerateDirectories())
            {
                ///Add name of folder
                string name = classFolder.Name;

                ///Upload all files in aarray
                FileInfo[] files = GetFilesByExtensions(classFolder, ".jpg", ".tif").ToArray();

                //Shuffle objects in array
                Vector.Shuffle(files);

                //For each image complite some easy operations
                for (int i = 0; i < files.Length; i++)
                {
                    //Uploat only train images
                    //70%
                    if ((i / (double)files.Length) < 0.7)
                    {
                        //Add file
                        FileInfo file = files[i];

                        //Create image from file
                        Bitmap image = (Bitmap)Bitmap.FromFile(file.FullName);

                        //Use detector
                        CannyEdgeDetector filterCanny = new CannyEdgeDetector();

                        //Apply changes
                        filterCanny.ApplyInPlace(image);

                        //Add some information of image
                        string shortName = file.Name;
                        int    imageKey  = j;

                        //Add image to dictionary
                        originalTrainImages.Add(j, image);

                        //Save correct key of class for image
                        outputsResult[j] = k;
                        j++;
                    }
                }
                //Change key of folder
                k++;
            }

            //Create teacher for svm, using Histogram Intersection
            var teacher = new MulticlassSupportVectorLearning <HistogramIntersection>()
            {
                //Add leaner params
                Learner = (param) => new SequentialMinimalOptimization <HistogramIntersection>()
                {
                    //Create kernel with optimal params
                    Kernel = new HistogramIntersection(0.25, 1),
                }
            };

            //Create KMeans algr
            var kmodes = new KModes <byte>(numberOfContour, new Hamming());

            //Create detector
            var detector = new FastRetinaKeypointDetector();

            //Create bagOfContourFragments
            bagOfContourFragments = new BagOfVisualWords(numberOfContour);

            //Learned bagOfContourFragments
            bagOfContourFragments.Learn(originalTrainImages.Values.ToArray());

            //For each iamge add inputs info
            for (int i = 0; i < originalTrainImages.Count; i++)
            {
                Bitmap image = originalTrainImages[i] as Bitmap;

                inputsInfo[i] = (bagOfContourFragments as ITransform <Bitmap, double[]>).Transform(image);
            }

            //Save condition of bagOfContourFragments
            BinarySave.WriteBinary(bagOfContourFragments);

            //Teach svm
            multiSVM = teacher.Learn(inputsInfo, outputsResult);

            //Save condition of svm
            BinarySave.WriteBinary(multiSVM);
        }
Ejemplo n.º 26
0
        /// <summary>
        ///   This methods computes the Bag-of-Visual-Words with the training images.
        /// </summary>
        ///
        private void btnBagOfWords_Click(object sender, EventArgs e)
        {
            int numberOfWords = (int)numWords.Value;


            Stopwatch sw1 = Stopwatch.StartNew();

            IBagOfWords <Bitmap> bow;

            // Check if we will use SURF or FREAK as the feature detector
            if (rbSurf.Checked)
            {
                // We will use SURF, so we can use a standard clustering
                // algorithm that is based on Euclidean distances. A good
                // algorithm for clustering codewords is the Binary Split
                // variant of the K-Means algorithm.

                // Create a Binary-Split clustering algorithm
                BinarySplit binarySplit = new BinarySplit(numberOfWords);

                // Create bag-of-words (BoW) with the given algorithm
                BagOfVisualWords surfBow = new BagOfVisualWords(binarySplit);

                // Compute the BoW codebook using training images only
                bow = surfBow.Learn(originalTrainImages.Values.ToArray());
            }
            else if (rbFreak.Checked)
            {
                // We will use the FREAK detector. The features generated by FREAK
                // are represented as bytes. While it is possible to transform those
                // to standard double vectors, we will demonstrate how to use a non-
                // Euclidean distance based algorithm to generate codewords for it.

                // Note: Using Binary-Split with normalized FREAK features would
                // possibly work better than the k-modes. This is just an example.

                // Create a k-Modes clustering algorithm
                var kmodes = new KModes <byte>(numberOfWords, new Hamming());

                // Create a FREAK detector explicitly (if no detector was passed,
                // the BagOfVisualWords would be using a SURF detector by default).
                var freak = new FastRetinaKeypointDetector();

                // Create bag-of-words (BoW) with the k-modes clustering and FREAK detector
                var freakBow = new BagOfVisualWords <FastRetinaKeypoint, byte[]>(freak, kmodes);

                // Compute the BoW codebook using training images only
                bow = freakBow.Learn(originalTrainImages.Values.ToArray());
            }
            else
            {
                // We will use HOG, so we can use a standard clustering
                // algorithm that is based on Euclidean distances. A good
                // algorithm for clustering codewords is the Binary Split
                // variant of the K-Means algorithm.

                // Create a Binary-Split clustering algorithm
                BinarySplit binarySplit = new BinarySplit(numberOfWords);

                // Create a HOG detector explicitly (if no detector was passed,
                // the BagOfVisualWords would be using a SURF detector by default).
                var hog = new HistogramsOfOrientedGradients();

                // Create bag-of-words (BoW) with the given algorithm
                var hogBow = BagOfVisualWords.Create(hog, binarySplit);

                // Compute the BoW codebook using training images only
                bow = hogBow.Learn(originalTrainImages.Values.ToArray());
            }

            sw1.Stop();

            // Now that we have already created and computed the BoW model, we
            // will use it to extract representations for each of the images in
            // both training and testing sets.

            Stopwatch sw2 = Stopwatch.StartNew();

            // Extract features for all images
            foreach (ListViewItem item in listView1.Items)
            {
                // Get item image
                Bitmap image = originalImages[item.ImageKey] as Bitmap;

                // Get a feature vector representing this image
                double[] featureVector = (bow as ITransform <Bitmap, double[]>).Transform(image);

                // Represent it as a string so we can show it onscreen
                string featureString = featureVector.ToString(DefaultArrayFormatProvider.InvariantCulture);

                // Show it in the visual grid
                if (item.SubItems.Count == 2)
                {
                    item.SubItems[1].Text = featureString;
                }
                else
                {
                    item.SubItems.Add(featureString);
                }

                // Retrieve the class labels, that we had stored in the Tag
                int classLabel = (item.Tag as Tuple <double[], int>).Item2;

                // Now, use the Tag to store the feature vector too
                item.Tag = Tuple.Create(featureVector, classLabel);
            }

            sw2.Stop();

            lbStatus.Text = "BoW constructed in " + sw1.Elapsed + "s. Features extracted in " + sw2.Elapsed + "s.";
            btnSampleRunAnalysis.Enabled = true;
        }
Ejemplo n.º 27
0
        /// <summary>
        ///   This methods computes the Bag-of-Visual-Words with the training images.
        /// </summary>
        ///
        private void btnBagOfWords_Click(object sender, EventArgs e)
        {
            int numberOfWords = (int)numWords.Value;


            // Create a Binary-Split clustering algorithm
            BinarySplit binarySplit = new BinarySplit(numberOfWords);

            Stopwatch sw1 = Stopwatch.StartNew();

            IBagOfWords <Bitmap> bow;

            if (rbSurf.Checked)
            {
                // Create bag-of-words (BoW) with the given algorithm
                var surfBow = new BagOfVisualWords(binarySplit);

                // Compute the BoW codebook using training images only
                surfBow.Compute(originalTrainImages.Values.ToArray());

                bow = surfBow;
            }

            else
            {
                // Alternative creation using the FREAK detector

                // Create a Binary-Split clustering algorithm
                var kmodes   = new KModes <byte>(numberOfWords, new Hamming());
                var detector = new FastRetinaKeypointDetector();

                // Create bag-of-words (BoW) with the given algorithm
                var freakBow = new BagOfVisualWords <FastRetinaKeypoint, byte[]>(detector, kmodes);

                // Compute the BoW codebook using training images only
                freakBow.Compute(originalTrainImages.Values.ToArray());

                bow = freakBow;
            }

            sw1.Stop();

            Stopwatch sw2 = Stopwatch.StartNew();

            // Extract features for all images
            foreach (ListViewItem item in listView1.Items)
            {
                // Get item image
                Bitmap image = originalImages[item.ImageKey] as Bitmap;

                // Process image
                double[] featureVector = bow.GetFeatureVector(image);
                string   featureString = featureVector.ToString(DefaultArrayFormatProvider.InvariantCulture);

                if (item.SubItems.Count == 2)
                {
                    item.SubItems[1].Text = featureString;
                }
                else
                {
                    item.SubItems.Add(featureString);
                }

                int classLabel = (item.Tag as Tuple <double[], int>).Item2;
                item.Tag = Tuple.Create(featureVector, classLabel);
            }

            sw2.Stop();

            lbStatus.Text = "BoW constructed in " + sw1.Elapsed + "s. Features extracted in " + sw2.Elapsed + "s.";
            btnSampleRunAnalysis.Enabled = true;
        }
        public void ProcessImageTest2()
        {
            Bitmap lena = Accord.Imaging.Image.Clone(Properties.Resources.lena512);

            FastRetinaKeypointDetector target = new FastRetinaKeypointDetector();

            target.ComputeDescriptors = FastRetinaKeypointDescriptorType.Extended;

            List <FastRetinaKeypoint> actual = target.ProcessImage(lena);

            string code;

            Assert.AreEqual(1283, actual.Count);

            int i = 0;

            Assert.AreEqual(223, actual[i].X);
            Assert.AreEqual(45, actual[i].Y);
            Assert.AreEqual(80.122163710144434, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000000000011110111100011100000000000000100010011100111111111111111111111111100111100111100000010001100000000100010000000000000000000000011111111110011110111111111100111100011100111100011100000000000000000000000000000000000000000000011100111000011100011111111111110111111111111111111111100111111111100111100111100111100111100001110001100001110001100000000000000000000000000000000000100010000000100011000001011110011110001110011110001111111111111100111111111100111110011100111100011100111100011100000010001000000010001100000100000000100010000000100011000001000000011100111100011100111100011100011111111111110011111111110011111111111111111111100111111111100111110111100111111111100111100111100111110111100001110001100001110001100001110001100000001100011000011100011000001100011000000011100011000011100011000011100011000011011111111110011110011110011111011110001110111100111100011100111100011100111100011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("00788f030091f3ffff9fe7811820020000fee7fdcfe33c0e0000000000cee1f8fffeff7ffee7799e876338060000004004c4a0e7711eff3ffff3398ff3381001310810013108388ff338fe3ffff3fffff99feff99fe7f91e8ee1188e0163380663c0311cc331ec7f9ee77bdcf3388ff338000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("AHiPAwCR8///n+eBGCACAAD+5/3P4zwOAAAAAADO4fj//v9//ud5nodjOAYAAABABMSg53Ee/z//8zmP8zgQATEIEAExCDiP8zj+P//z///5n+/5n+f5Ho7hGI4BYzgGY8AxHMMx7H+e53vc8ziP8zgAAAAAAAAAAAAAAAAAAAA=", code);

            i = 124;
            Assert.AreEqual(141.0, actual[i].X);
            Assert.AreEqual(184.0, actual[i].Y);
            Assert.AreEqual(158.74949449286677, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000000001001110111110011100000110000000000000011100011001111011110011100111100011100111100001110001110000001000001000000011100011000001001110001110000110011100011100011110011100011100001100001110001110000110000001100011000001000000011100011100001100111001110001100000100000100001100001000001000000000001100001000001000000001001110001100000100000101110001100011000001000001001100011100011100001100111011111001110001100000100000100110100001000001000000000000000000000001000001000000000000000000001001110001100000100000100110100110011100011000001100001011111011110011100011100001110111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000110001100000100000000110000110001110001100011000001000001001100001100011110011100011100001110111111111111111011111001110001100000100000100110100110001111100001000001000000000000000000000000011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("00729f83018063de731ee7e13810041c831c87398ee7380cc761600c028ec39c6310842108802108906310748c4190711ce63ec720c842100000100400801c8320cb1c83a1ef390ef7ff07000000000000000000000000408c4180611c63106418cf71b8ffbfcf3108b28c0f4100000007000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("AHKfgwGAY95zHufhOBAEHIMchzmO5zgMx2FgDAKOw5xjEIQhCIAhCJBjEHSMQZBxHOY+xyDIQhAAABAEAIAcgyDLHIOh7zkO9/8HAAAAAAAAAAAAAAAAQIxBgGEcYxBkGM9xuP+/zzEIsowPQQAAAAcAAAAAAAAAAAAAAAAAAAA=", code);

            i = 763;
            Assert.AreEqual(104, actual[i].X);
            Assert.AreEqual(332, actual[i].Y);
            Assert.AreEqual(-174.28940686250036, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000010000000010010110010110000011000000000000000000001000011000110000110001100000110001111011111111111110000000000000000000000000000000011111111111111110000000000000001100000000000000000100000011000110100110110000000000000000000000000000001000001101101011111111111110110111110000000000000000100001000000000000000000000000000111111111111111111111111110000000000000000000001000100000000000000000000001000101111111111111111111111111110110000000000000000000001000100000111111111111111111111111101101111111111111111111111111111111110000000000000001100101001101101001111111111111111111111111101101101111111111111111111111111111111111110011111111111101101111101101101001000000000000000000100001001101101000000111111111111111111111111111111111111110010110111111101101111101101101001000100000110001100001101101101101101001000100111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("20409a0603004018c3188cf7ff01000000feff01000300088c6503000000c1d6ffb70f0010020000e0ffff7f000010010080e8ffffff06000011fcffffb7ffffffff0080295bfeffffb7fdffffff3fff6fdf960000846c81ffffffff9ff6b76f4b0463d8b625f2ffffffffffffffffff3f000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("IECaBgMAQBjDGIz3/wEAAAD+/wEAAwAIjGUDAAAAwdb/tw8AEAIAAOD//38AABABAIDo////BgAAEfz//7f/////AIApW/7//7f9////P/9v35YAAIRsgf////+f9rdvSwRj2LYl8v///////////z8AAAAAAAAAAAAAAAAAAAA=", code);

            i = 1042;
            Assert.AreEqual(116, actual[i].X);
            Assert.AreEqual(410, actual[i].Y);
            Assert.AreEqual(-86.11209043916692, actual[i].Orientation, 1e-10);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000000001001111111110011100000000000001100010011100111000110001000001100010000011110111111000110001000000000000000000000001100010000011001110011101101110011110111111011110000000000000001000000100001000000100010000000000000000000000001100010001011100111000110001000001100011100011100111011011100111110011110111111011110111111000000000000000100000100000000000000000000000000000000001100010011011100111110011001111011111101111011111111111111111111111111111111111111110001100010011011100111110011000000000000000000100010100001100000000000000000001000001000001000000011110111111111111111111111110111001111011111101111111111111111011101111111111111111111111111111110111111111111111111111111111111111110111111000110001000001100011101001100001100000000000000000001000001000001000000000000011100111011011100111111011100111000011111111011111111111111111111111011111001111111110111111111111111111111110111110011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("00f29f038091738c6004efc708000018c19cdb79bf07000442200200008ce81c2318c7b99dcffbbd1f0010040000006064e733eff7feffffffff31b2f3190080280c0080200878ffff7fe7fdfeffddffffffefffffffff7e8c605c860100100401c0b99ddf39fcfbfffffbfcf7fffff739000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("APKfA4CRc4xgBO/HCAAAGMGc23m/BwAEQiACAACM6BwjGMe5nc/7vR8AEAQAAABgZOcz7/f+/////zGy8xkAgCgMAIAgCHj//3/n/f7/3f///+//////foxgXIYBABAEAcC5nd85/Pv///v89///9zkAAAAAAAAAAAAAAAAAAAA=", code);

            i = 1282;
            Assert.AreEqual(425.0, actual[i].X);
            Assert.AreEqual(488.0, actual[i].Y);
            Assert.AreEqual(-70.722526916337571, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("0000110000000000111110000010011011010110110110000000000011111011111111111111110111110111100000011010010000111110111100010110110110100010011111011110011111111111111111111110111110111100011100011111011110001110000111110111100011100010111110111100111110111111111111111111111011111111111111111111111111111111111111110111110111100011111011110011111011110000111110111100111110111100010111110111100111110111100011111111111111011111011110001111111111111111111111111110111110111111111110111110111100011100011111011111011111011110001110000111111111110111110111100011100010111111111110111110111100011100111111111111111111111111111011111011111111111111111111111111111111111111111111111111111111111111110111110111100111111111111011111011110001110011110000111111111110111110111100011100011000001111111111110111110111100011100111100011111111111111111111111111011111011110011111111111111111111111111110111110111100111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", code);
            code = actual[i].ToHex();
            Assert.AreEqual("30001f646b1b00dfffbfef81257c8fb645bee7fffff73d8eef71f81e47dff3fdff7fffffffffffbec7f77c0fdff33dfa9eeff1fffb1efffffff7fddff738beef7b1cfeef7b1cfddff738fffffff7fdfffffffffffffffb9efff73dcec3ff7d8f63f0ffbec779fcffffef7bfeffffdff73c000000000000000000000000000000", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("MAAfZGsbAN//v++BJXyPtkW+5///9z2O73H4Hkff8/3/f///////vsf3fA/f8z36nu/x//se////9/3f9zi+73sc/u97HP3f9zj////3/f/////////7nv/3Pc7D/32PY/D/vsd5/P//73v+///f9zwAAAAAAAAAAAAAAAAAAAA=", code);
        }
Ejemplo n.º 29
0
        private void process1()
        {
            var bitmap1 = (Bitmap)sourcebox1.Image;
            var bitmap2 = (Bitmap)sourcebox2.Image;
            var hash1   = ImagePhash.ComputeDigest(bitmap1.ToLuminanceImage());
            var hash2   = ImagePhash.ComputeDigest(bitmap2.ToLuminanceImage());
            var score   = ImagePhash.GetCrossCorrelation(hash1, hash2);

            Console.WriteLine("score: {0}", score);

            //threshold value
            var thres = new Threshold(110);

            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
            // apply the filter to the model
            Bitmap grey1 = filter.Apply(bitmap1);

            thres.ApplyInPlace(grey1);

            // Apply the filter to the observed image
            Bitmap grey2 = filter.Apply(bitmap2);

            thres.ApplyInPlace(grey2);

            int modelPoints = 0, matchingPoints = 0;

            var skewChecker     = new DocumentSkewChecker();
            var angle1          = skewChecker.GetSkewAngle(grey1);
            var rotationFilter1 = new RotateBicubic(-angle1);

            rotationFilter1.FillColor = Color.White;
            grey1 = rotationFilter1.Apply(grey1);

            var angle2          = skewChecker.GetSkewAngle(grey2);
            var rotationFilter2 = new RotateBicubic(-angle2);

            rotationFilter2.FillColor = Color.White;
            grey2 = rotationFilter2.Apply(grey2);

            //CorrelationMatching matcher = new CorrelationMatching(5, grey1, grey2);
            //var results = matcher.GetHashCode();
            var detector = new FastCornersDetector(15);
            var freak    = new FastRetinaKeypointDetector(detector);

            FastRetinaKeypoint[] features1 = freak.Transform(grey1).ToArray();
            modelPoints = features1.Count();

            Console.WriteLine("count: {0}", modelPoints);

            FastRetinaKeypoint[] features2 = freak.Transform(grey2).ToArray();

            Console.WriteLine("count: {0}", features2.Count());

            KNearestNeighborMatching matcher = new KNearestNeighborMatching(7);

            //var length = 0;

            IntPoint[][] results = matcher.Match(features1, features2);
            matchingPoints = results[0].Count(); // similarity of image1 to image2
            ////matchingPoints = results[1].Count(); // similarity of image2 to image1

            Console.WriteLine("matched points: {0}", matchingPoints);

            sourcebox1.Image = bitmap1;
            sourcebox2.Image = bitmap2;
            var marker1 = new FeaturesMarker(features1, 30);
            var marker2 = new FeaturesMarker(features2, 30);



            double similPercent = 0;

            if (matchingPoints <= 0)
            {
                similPercent = 0.0f;
            }
            similPercent = (matchingPoints * 100d) / (double)modelPoints;

            Console.WriteLine("score: {0}", similPercent);

            simil1.Text = similPercent.ToString("##.##") + "%";
            simil2.Text = (score * 100.00d).ToString("##.##") + "%";

            angle_text.Text  = angle2.ToString("##.##") + "°";
            resultbox1.Image = marker1.Apply(grey1);
            resultbox2.Image = marker2.Apply(grey2);
        }
Ejemplo n.º 30
0
        /// <summary>
        ///   This methods computes the Bag-of-Visual-Words with the training images.
        /// </summary>
        /// 
        private void btnBagOfWords_Click(object sender, EventArgs e)
        {
            int numberOfWords = (int)numWords.Value;


            // Create a Binary-Split clustering algorithm
            BinarySplit binarySplit = new BinarySplit(numberOfWords);

            Stopwatch sw1 = Stopwatch.StartNew();

            IBagOfWords<Bitmap> bow;

            if (rbSurf.Checked)
            {
                // Create bag-of-words (BoW) with the given algorithm
                var surfBow = new BagOfVisualWords(binarySplit);

                // Compute the BoW codebook using training images only
                surfBow.Compute(originalTrainImages.Values.ToArray());

                bow = surfBow;
            }

            else
            {

                // Alternative creation using the FREAK detector

                // Create a Binary-Split clustering algorithm
                var kmodes = new KModes<byte>(numberOfWords, Distance.BitwiseHamming);
                var detector = new FastRetinaKeypointDetector();

                // Create bag-of-words (BoW) with the given algorithm
                var freakBow = new BagOfVisualWords<FastRetinaKeypoint, byte[]>(detector, kmodes);

                // Compute the BoW codebook using training images only
                freakBow.Compute(originalTrainImages.Values.ToArray());

                bow = freakBow;
            }

            sw1.Stop();

            Stopwatch sw2 = Stopwatch.StartNew();

            // Extract features for all images
            foreach (ListViewItem item in listView1.Items)
            {
                // Get item image
                Bitmap image = originalImages[item.ImageKey] as Bitmap;

                // Process image
                double[] featureVector = bow.GetFeatureVector(image);
                string featureString = featureVector.ToString(DefaultArrayFormatProvider.InvariantCulture);

                if (item.SubItems.Count == 2)
                    item.SubItems[1].Text = featureString;
                else item.SubItems.Add(featureString);

                int classLabel = (item.Tag as Tuple<double[], int>).Item2;
                item.Tag = Tuple.Create(featureVector, classLabel);
            }

            sw2.Stop();

            lbStatus.Text = "BoW constructed in " + sw1.Elapsed + "s. Features extracted in " + sw2.Elapsed + "s.";
            btnSampleRunAnalysis.Enabled = true;
        }
        public void ProcessImageTest()
        {
            Bitmap lena = Accord.Imaging.Image.Clone(Properties.Resources.lena512);

            FastRetinaKeypointDetector target = new FastRetinaKeypointDetector();

            List <FastRetinaKeypoint> actual = target.ProcessImage(lena);

            string code;

            Assert.AreEqual(1283, actual.Count);

            int i = 0;

            Assert.AreEqual(223, actual[i].X);
            Assert.AreEqual(45, actual[i].Y);
            Assert.AreEqual(80.122163710144434, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("00101100101000101100000010111000110111111010111011110000011011110111111111101001011000111111010110100110101001000010100000001100100000111110110100000010100010010000100000110000100010110000000101110001100100101100011010111101100100110101111110000100010100111101100001010101110010000001100111111010100001111000111001101000011101111011110111001101111010101101001111110101010100000100100100101100101010011010011000000000001010000110101010011000111001111011111101110101110011100001001010110010100100001000101001010011", code);
            code = actual[i].ToHex();
            Assert.AreEqual("3445031dfb750ff6fe97c6af65251430c1b74091100cd1808e4963bdc9fa21ca1baa13985fe17116eebdb357cbaf0a9234956500145619e7fdae73484d0951ca", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("NEUDHft1D/b+l8avZSUUMMG3QJEQDNGAjkljvcn6IcobqhOYX+FxFu69s1fLrwqSNJVlABRWGef9rnNITQlRyg==", code);

            i = 124;
            Assert.AreEqual(141.0, actual[i].X);
            Assert.AreEqual(184.0, actual[i].Y);
            Assert.AreEqual(158.74949449286677, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("11111000010001010000011000000010000100100010010101000010100000011110101010110111001110010110111110010101100001000100010100001000110010000001010000010000000001010011010110000010101110110000001000010000100000010101011010111011110000001011101110001011100001110010000001000000001011000010100010001001100001101000010100001000000001001010110100000000001010011101001010000111011010011000110010000100110000100010011001010000001010010110001000010000111000011000000000100100110000100001001000010010100100000000100001000001", code);
            code = actual[i].ToHex();
            Assert.AreEqual("1fa2604048a4428157ed9cf6a921a210132808a0ac41dd4008816add03ddd1e1040234149161a11020b500944be196312143640a944608870124434848091082", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("H6JgQEikQoFX7Zz2qSGiEBMoCKCsQd1ACIFq3QPd0eEEAjQUkWGhECC1AJRL4ZYxIUNkCpRGCIcBJENISAkQgg==", code);

            i = 763;
            Assert.AreEqual(104, actual[i].X);
            Assert.AreEqual(332, actual[i].Y);
            Assert.AreEqual(-174.28940686250036, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("01010001111011001100011000010110101011111010010001000101001111110111111101101101111000101101010111010110111010001110001011011100111000010000010111100000010010010101010001010001110100010101111011000001101100111001001100001000101100010111011110111100111101110100011000100101001010010011010000111110000100000000000011001000000011111011010011011001001010011101010011111101001001010111000001010100011011110111010000010101100000010110110101111100101111111000100011111001100011100000110011011011100000001010100101011101", code);
            code = actual[i].ToHex();
            Assert.AreEqual("8a376368f525a2fcfeb647ab6b17473b87a007922a8a8b7a83cdc9108dee3def62a4942c7c080013f02d9b942bbfa40e2af62ea881b63efd119f7130db0195ba", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("ijdjaPUlovz+tkeraxdHO4egB5Iqiot6g83JEI3uPe9ipJQsfAgAE/Atm5Qrv6QOKvYuqIG2Pv0Rn3Ew2wGVug==", code);

            i = 1042;
            Assert.AreEqual(116, actual[i].X);
            Assert.AreEqual(410, actual[i].Y);
            Assert.AreEqual(-86.11209043916692, actual[i].Orientation, 1e-10);
            code = actual[i].ToBinary();
            Assert.AreEqual("11110111010011000010101001011011010101100111010011011101001111010110001010110000111001010111101011001011001001101101100011011011110111110000010111111000000000010001001000010110101010010001100011011110101000100101100010101100000100111011101100010110001000111000100001110100001000110001110011111011000001100000111001001000011111111011010101001101110000010101001110111101011100001100110110000100111010100010000001000000011110000110111010011000111100111011111110110101110011100000001001110010100100001000101001110011", code);
            code = actual[i].ToHex();
            Assert.AreEqual("ef3254da6a2ebbbc460da75ed3641bdbfba01f80486895187b451a35c8dd68c4112ec438df607012feadb283cabd0eb3215704021e7619cffdad73404e0951ce", code);
            code = actual[i].ToBase64();
            Assert.AreEqual("7zJU2mouu7xGDade02Qb2/ugH4BIaJUYe0UaNcjdaMQRLsQ432BwEv6tsoPKvQ6zIVcEAh52Gc/9rXNATglRzg==", code);

            i = 1282;
            Assert.AreEqual(425.0, actual[i].X);
            Assert.AreEqual(488.0, actual[i].Y);
            Assert.AreEqual(-70.722526916337571, actual[i].Orientation);
            code = actual[i].ToBinary();
            Assert.AreEqual("10111011111111011101111000011111111101110111111011111111111111111111111111111011011110111111111111111111011011101001111101101110111101111111101111111110111011101111111010110011100100111110101101111111111110111111111110111111111111111111011011101101110111111111111010110101110111000001010101111111100111011000111111110111011100111111111111111101111110101111111111110111010101000111011100111111101011011011111100011011111011111111101111111001111011111011111111110111111111110001001110111110100110101111111001010111", code);
            code = actual[i].ToHex();
            Assert.AreEqual("ddbf7bf8ef7effffffdfdeffff76f976efdf7f777fcdc9d7fedffffdff6fb7fb7fad3ba8feb9f1efceffbf5fffef2aeefcb5fdd8f7df9ff7fdefffc87d597fea", code);
        }