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 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))); }
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)); }
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); }
/// <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))); } } }
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; }
// 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; } } } }