Inheritance: ICornersDetector
        /// <summary>
        /// Features from Accelerated Segment Test (FAST) corners detector.
        /// <para>Accord.NET internal call. Please see: <see cref="Accord.Imaging.FastCornersDetector"/> for details.</para>
        /// </summary>
        /// <param name="im">Image.</param>
        /// <param name="threshold">The suppression threshold. Decreasing this value increases the number of points detected by the algorithm.</param>
        /// <returns>Interest point locations.</returns>
        public static List<IntPoint> CornerFeaturesDetector(this Image<Gray, byte> im, int threshold = 20)
        {
            FastCornersDetector fast = new FastCornersDetector(threshold);
            var points = fast.ProcessImage(im.ToAForgeImage(copyAlways: false, failIfCannotCast: true));

            return points;
        }
Ejemplo n.º 2
0
        public List <Rg.Point3d> GetFastCorners()
        {
            Ai.FastCornersDetector corners = new Ai.FastCornersDetector();
            if (Threshold >= 0)
            {
                corners.Threshold = Threshold;
            }

            return(corners.ProcessImage(bitmap).ToRhinoPoints(bitmap.Height));
        }
        /// <summary>
        /// Features from Accelerated Segment Test (FAST) corners detector.
        /// <para>Accord.NET internal call. Please see: <see cref="Accord.Imaging.FastCornersDetector"/> for details.</para>
        /// </summary>
        /// <param name="im">Image.</param>
        /// <param name="threshold">The suppression threshold. Decreasing this value increases the number of points detected by the algorithm.</param>
        /// <returns>Interest point locations.</returns>
        public static List<Point> CornerFeaturesDetector(this Gray<byte>[,] im, int threshold = 20)
        {
            FastCornersDetector fast = new FastCornersDetector(threshold);

            List<Point> points;
            using (var uImg = im.Lock())
            {
                points = fast.ProcessImage(uImg.AsAForgeImage())
                             .Select(x => x.ToPoint())
                             .ToList();
            }
            
            return points;
        }
        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);
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Open a image
            Bitmap lenna = Fast.Properties.Resources.lena512;

            // Create a new SURF Features Detector using the given parameters
            FastCornersDetector fast = new FastCornersDetector();
            fast.Threshold = (int)numThreshold.Value;
            fast.Suppress = true;

            // Create a new AForge's Corner Marker Filter
            CornersMarker corners = new CornersMarker(fast, Color.White);

            // Apply the filter and display it on a picturebox
            pictureBox1.Image = corners.Apply(lenna);
        }
        public void ProcessImageTest2()
        {
            UnmanagedImage image = UnmanagedImage.FromManagedImage(Accord.Imaging.Image.Clone(Properties.Resources.lena512));

            FastCornersDetector target = new FastCornersDetector();
            target.Suppress = true;
            target.Threshold = 40;

            List<IntPoint> actual = target.ProcessImage(image);

            Assert.AreEqual(324, actual.Count);
            Assert.AreEqual(506, actual[0].X);
            Assert.AreEqual(4, actual[0].Y);
            Assert.AreEqual(152, actual[6].X);
            Assert.AreEqual(75, actual[6].Y);
            Assert.AreEqual(416, actual[11].X);
            Assert.AreEqual(115, actual[11].Y);
            Assert.AreEqual(140, actual[65].X);
            Assert.AreEqual(246, actual[65].Y);
            Assert.AreEqual(133, actual[73].X);
            Assert.AreEqual(253, actual[73].Y);
        }
        public void ProcessImageTest()
        {
            UnmanagedImage image = UnmanagedImage.FromManagedImage(Accord.Imaging.Image.Clone(Properties.Resources.sample_black));

            FastCornersDetector target = new FastCornersDetector();
            target.Suppress = false;
            target.Threshold = 20;

            List<IntPoint> actual = target.ProcessImage(image);

            Assert.AreEqual(237, actual.Count);
            Assert.AreEqual(404, actual[0].X);
            Assert.AreEqual(35, actual[0].Y);
            Assert.AreEqual(407, actual[6].X);
            Assert.AreEqual(36, actual[6].Y);
            Assert.AreEqual(407, actual[11].X);
            Assert.AreEqual(38, actual[11].Y);
            Assert.AreEqual(55, actual[65].X);
            Assert.AreEqual(135, actual[65].Y);
            Assert.AreEqual(103, actual[73].X);
            Assert.AreEqual(137, actual[73].Y);
        }
        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);
            }

        }
        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));
        }
Ejemplo n.º 10
0
        public void ProcessImageTest()
        {
            UnmanagedImage image = UnmanagedImage.FromManagedImage(Properties.Resources.sample_black);

            FastCornersDetector target = new FastCornersDetector();
            target.Suppress = false;
            target.Threshold = 20;

            List<IntPoint> actual = target.ProcessImage(image);
            /*
                        PointsMarker marker = new PointsMarker(actual.ToArray());
                        marker.Width = 3;
                        marker.MarkerColor = Color.FromArgb(255, 0, 0);
                        var markers = marker.Apply(image);
                        ImageBox.Show(markers.ToManagedImage(), PictureBoxSizeMode.Zoom);
                        */

            Assert.AreEqual(237, actual.Count);
            Assert.AreEqual(404, actual[0].X);
            Assert.AreEqual(35, actual[0].Y);
            Assert.AreEqual(407, actual[6].X);
            Assert.AreEqual(36, actual[6].Y);
            Assert.AreEqual(407, actual[11].X);
            Assert.AreEqual(38, actual[11].Y);
            Assert.AreEqual(55, actual[65].X);
            Assert.AreEqual(135, actual[65].Y);
            Assert.AreEqual(103, actual[73].X);
            Assert.AreEqual(137, actual[73].Y);
        }
Ejemplo n.º 11
0
        public void ProcessImageTest2()
        {
            UnmanagedImage image = UnmanagedImage.FromManagedImage(Properties.Resources.lena512);

            FastCornersDetector target = new FastCornersDetector();
            target.Suppress = true;
            target.Threshold = 40;

            List<IntPoint> actual = target.ProcessImage(image);

            /*
                        PointsMarker marker = new PointsMarker(actual.ToArray());
                        marker.Width = 3;
                        marker.MarkerColor = Color.FromArgb(255, 0, 0);
                        var markers = marker.Apply(image);
                        ImageBox.Show(markers.ToManagedImage(), PictureBoxSizeMode.Zoom);
            */

            Assert.AreEqual(324, actual.Count);
            Assert.AreEqual(506, actual[0].X);
            Assert.AreEqual(4, actual[0].Y);
            Assert.AreEqual(152, actual[6].X);
            Assert.AreEqual(75, actual[6].Y);
            Assert.AreEqual(416, actual[11].X);
            Assert.AreEqual(115, actual[11].Y);
            Assert.AreEqual(140, actual[65].X);
            Assert.AreEqual(246, actual[65].Y);
            Assert.AreEqual(133, actual[73].X);
            Assert.AreEqual(253, actual[73].Y);
        }