Harris Corners Detector.

This class implements the Harris corners detector.

Sample usage:

// create corners detector's instance HarrisCornersDetector hcd = new HarrisCornersDetector( ); // process image searching for corners Point[] corners = hcd.ProcessImage( image ); // process points foreach ( Point corner in corners ) { // ... }

References: P. D. Kovesi. MATLAB and Octave Functions for Computer Vision and Image Processing. School of Computer Science and Software Engineering, The University of Western Australia. Available in: http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/Spatial/harris.m C.G. Harris and M.J. Stephens. "A combined corner and edge detector", Proceedings Fourth Alvey Vision Conference, Manchester. pp 147-151, 1988. Alison Noble, "Descriptions of Image Surfaces", PhD thesis, Department of Engineering Science, Oxford University 1989, p45.

Inheritance: ICornersDetector
Esempio n. 1
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        ///
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        ///
        public object Clone()
        {
            var clone = new HarrisCornersDetector();

            clone.initialize(measure, k, threshold, sigma, r, size);
            return(clone);
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Open a image
            Bitmap lenna = Properties.Resources.lena512;

            double sigma = (double)numSigma.Value;
            float k = (float)numK.Value;
            float threshold = (float)numThreshold.Value;

            // Create a new Harris Corners Detector using the given parameters
            HarrisCornersDetector harris = new HarrisCornersDetector(k)
            {
                Measure = checkBox1.Checked ?
                    HarrisCornerMeasure.Harris : HarrisCornerMeasure.Noble,

                Threshold = threshold,
                Sigma = sigma
            };

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

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

            HarrisCornersDetector target = new HarrisCornersDetector(0.04f, 1000f, 1.4);
            target.Suppression = 1;

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

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

            /*
                        Assert.AreEqual(4, actual.Count);
                        Assert.IsTrue(actual.Contains(new IntPoint(3, 3)));
                        Assert.IsTrue(actual.Contains(new IntPoint(14, 3)));
                        Assert.IsTrue(actual.Contains(new IntPoint(3, 14)));
                        Assert.IsTrue(actual.Contains(new IntPoint(14, 14)));
            */

            Assert.AreEqual(4, actual.Count);
            Assert.IsTrue(actual.Contains(new IntPoint(3, 3)));
            Assert.IsTrue(actual.Contains(new IntPoint(12, 3)));
            Assert.IsTrue(actual.Contains(new IntPoint(3, 12)));
            Assert.IsTrue(actual.Contains(new IntPoint(12, 12)));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        ///
        protected override object Clone(ISet <PixelFormat> supportedFormats)
        {
            var clone = new HarrisCornersDetector();

            clone.SupportedFormats = supportedFormats;
            clone.initialize(measure, k, threshold, sigma, r, size);
            return(clone);
        }
Esempio n. 5
0
        public List <Rg.Point3d> GetHarrisCorners()
        {
            Ai.HarrisCornersDetector corners = new Ai.HarrisCornersDetector();
            if (Threshold >= 0)
            {
                corners.Threshold = Threshold;
            }
            if (Value >= 0)
            {
                corners.Sigma = Value;
            }

            return(corners.ProcessImage(bitmap).ToRhinoPoints(bitmap.Height));
        }
Esempio n. 6
0
        private void BtnHarris_OnClick(object sender, RoutedEventArgs e)
        {
            // Step 1: Detect feature points using Harris Corners Detector
            HarrisCornersDetector harris = new HarrisCornersDetector(0.04f, 1000f);
            harrisPoints1 = harris.ProcessImage(img1).ToArray();
            harrisPoints2 = harris.ProcessImage(img2).ToArray();

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

            // Concatenate the two images together in a single image (just to show on screen)
            Concatenate concatenate = new Concatenate(img1mark);
            PictureBox.Source = concatenate.Apply(img2mark);
        }
        public void ProcessImageTest2()
        {
            UnmanagedImage image = UnmanagedImage.FromManagedImage(Accord.Imaging.Image.Clone(Properties.Resources.sample_black));

            HarrisCornersDetector target = new HarrisCornersDetector(HarrisCornerMeasure.Noble, 700f, 1.4, 1);

            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(actual.Count, 42);
        }
Esempio n. 8
0
 /// <summary>
 /// Detect keypoints in images using Harris corner detector from Accord.NET library
 /// http://accord-framework.net/docs/html/T_Accord_Imaging_HarrisCornersDetector.htm
 /// </summary>
 private void detectKeypoints_Harris()
 {
     HarrisCornersDetector harris_detector = new HarrisCornersDetector(0.04f, 500f);
     for (int i = 0; i < input_images.Count; i++)
     {
         if (i != 0) //if not first image, calculate left side keypoints
         {
             keypoints.Add(harris_detector.ProcessImage(GetCroppedImage(input_images[i], ImageSection.Left)));
         }
         if (i != input_images.Count - 1) //if not last image, calculate right side keypoints
         {
             keypoints.Add(harris_detector.ProcessImage(GetCroppedImage(input_images[i], ImageSection.Right)));
         }
     }
 }
 /// <summary>
 ///   Creates a new object that is a copy of the current instance.
 /// </summary>
 /// 
 /// <returns>
 ///   A new object that is a copy of this instance.
 /// </returns>
 /// 
 public object Clone()
 {
     var clone = new HarrisCornersDetector();
     clone.initialize(measure, k, threshold, sigma, r, size);
     return clone;
 }
Esempio n. 10
0
        private bool GenerateKeypointMatches(Bitmap target, Bitmap frame, Rectangle prevTarget)
        {
            HarrisCornersDetector harrisDetector = new HarrisCornersDetector(HarrisCornerMeasure.Harris, 1000f, 1f, 2);
            targetKeyPoints=harrisDetector.ProcessImage(target).ToArray();
            frameKeyPoints=harrisDetector.ProcessImage(frame).ToArray();
            //Console.WriteLine("tr={0} fr={1}", targetKeyPoints.Length, frameKeyPoints.Length);
            if (targetKeyPoints.Length==0||frameKeyPoints.Length==0)
            {
                return false;
            }

            CorrelationMatching matcher=new CorrelationMatching(15);
            IntPoint[][] matches=matcher.Match(target, frame, targetKeyPoints, frameKeyPoints);
            targetMacthes=matches[0];
            frameMatches=matches[1];
            if (targetMacthes.Length<4||frameMatches.Length<4)
            {
                return false;
            }
            RansacHomographyEstimator ransac=new RansacHomographyEstimator(0.1, 0.50);
            MatrixH estiment = new MatrixH();
            try
            {

                estiment = ransac.Estimate(targetMacthes, frameMatches);
            }
            catch
            {
                return false;
            }
            IntPoint[] targetGoodMatch=targetMacthes.Submatrix(ransac.Inliers);
            IntPoint[] frameGoodMatch=frameMatches.Submatrix(ransac.Inliers);
            CalculatePosChange(targetGoodMatch, frameGoodMatch, prevTarget);
            return true;
        }
Esempio n. 11
0
        private void harris_Click(object sender, EventArgs e)
         {
            // Open a image
            Bitmap image = new Bitmap(sourcePic.Image);

            double sigma = 1.4;
            float k = 0.04f;
            float threshold = 20000;
            // Create a new Harris Corners Detector using the given parameters
            HarrisCornersDetector harris = new HarrisCornersDetector(k)
            {
                Threshold = threshold,
                Sigma = sigma
            };

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

            // Apply the filter and display it on a picturebox
            processedPic.Image = corners.Apply(image);
        }
Esempio n. 12
0
 private void UpdateDetector()
 {
     harris = new HarrisCornersDetector(configuration.K)
     {
         Threshold = configuration.Threshold,
         Sigma = configuration.Sigma
     };
     matcher = new KNearestNeighborMatching(configuration.NoNearestNeighborMatching);
 }
Esempio n. 13
0
        // PANORAMIC STICHING CODE
        // Accord.NET and AForge.NET frameworks and code examples provided from
        // http://www.codeproject.com/KB/recipes/automatic_panoramas.aspx
        private void panoramicStitchingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Save a copy of the current image, ask user to open another image to merge with
            Bitmap img2 = img;
            openToolStripMenuItem_Click(sender, e);

            // Check whether the current loaded image is different
            // (If the user cancelled the open image operation, the current image in the viewer
            // is still the same image object)
            if (img2 != img)
            {
                Bitmap img1 = img;

                AForge.IntPoint[] harrisPoints1;
                AForge.IntPoint[] harrisPoints2;

                AForge.IntPoint[] correlationPoints1;
                AForge.IntPoint[] correlationPoints2;

                MatrixH homography;

                // Use Harris Corners Detector to find points of interest
                HarrisCornersDetector harris = new HarrisCornersDetector(0.04f, 1000f);
                harrisPoints1 = harris.ProcessImage(img1).ToArray();
                harrisPoints2 = harris.ProcessImage(img2).ToArray();

                // This check fixes an out of bounds exception generated by matcher.Match() below when a
                // monocolour image (0 harris points) is stitched with a non-monocolour image
                if (harrisPoints1.Length == 0 || harrisPoints2.Length == 0)
                {
                    MessageBox.Show("Panoramic stitching cannot continue because at least one of the images does not contain any Harris points.", "Warning");
                }
                else
                {
                    // Match detected points using correlation
                    CorrelationMatching matcher = new CorrelationMatching(9);
                    AForge.IntPoint[][] matches = matcher.Match(img1, img2, harrisPoints1, harrisPoints2);

                    // Separate the two arrays
                    correlationPoints1 = matches[0];
                    correlationPoints2 = matches[1];

                    // Find homography matrix using RANSAC algorithm
                    RansacHomographyEstimator ransac = new RansacHomographyEstimator(0.001, 0.99);

                    // This check is to handle the ransac.Estimate() function
                    // which throws an exception if the array parameters do not contain at least 4 elements
                    if (correlationPoints1.Length < 4 || correlationPoints2.Length < 4)
                    {
                        MessageBox.Show("Panoramic stitching cannot continue because at least one of the images does not contain at least 4 correlation points.", "Warning");
                    }
                    else
                    {
                        homography = ransac.Estimate(correlationPoints1, correlationPoints2);

                        // Merge the images
                        Blend blend = new Blend(homography, img1);
                        img = blend.Apply(img2);

                        //save the image properly and resize main form
                        origImg.Dispose();
                        origImg = new Bitmap(img);
                        pictureBox.Image = img;
                        mainForm.ActiveForm.Width = img.Width + widthPad;
                        mainForm.ActiveForm.Height = img.Height + heightPad;
                    }
                }
            }
        }