public void FindContourTest2() { Bitmap bmp = Accord.Imaging.Image.Clone(Properties.Resources.hand2); BlobCounter bc = new BlobCounter(bmp); bc.ObjectsOrder = ObjectsOrder.Size; Blob[] blobs = bc.GetObjectsInformation(); bc.ExtractBlobsImage(bmp, blobs[0], true); List<IntPoint> expected = bc.GetBlobsEdgePoints(blobs[0]); Bitmap blob = blobs[0].Image.ToManagedImage(); BorderFollowing bf = new BorderFollowing(); List<IntPoint> actual = bf.FindContour(blob); foreach (IntPoint point in expected) Assert.IsTrue(actual.Contains(point)); IntPoint prev = actual[0]; for (int i = 1; i < actual.Count; i++) { IntPoint curr = actual[i]; Assert.IsTrue(System.Math.Abs(prev.X - curr.X) <= 1 && System.Math.Abs(prev.Y - curr.Y) <= 1); prev = curr; } IntPoint first = actual[0]; IntPoint last = actual[actual.Count - 1]; Assert.IsTrue(System.Math.Abs(first.X - last.X) <= 1 && System.Math.Abs(first.Y - last.Y) <= 1); }
public void FindDefectsTest() { Bitmap bmp = Accord.Imaging.Image.Clone(Properties.Resources.hand); Bitmap gray = Accord.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(bmp); BlobCounter bc = new BlobCounter(gray); bc.ObjectsOrder = ObjectsOrder.Size; Blob[] blobs = bc.GetObjectsInformation(); bc.ExtractBlobsImage(bmp, blobs[0], true); Bitmap blob = blobs[0].Image.ToManagedImage(); BorderFollowing bf = new BorderFollowing(); List<IntPoint> contour = bf.FindContour(blob); GrahamConvexHull graham = new GrahamConvexHull(); List<IntPoint> hull = graham.FindHull(contour); ConvexHullDefects hullDefects = new ConvexHullDefects(10); List<ConvexityDefect> defects = hullDefects.FindDefects(contour, hull); /* PointsMarker marker = new PointsMarker(hull, Color.Green, 10); marker.ApplyInPlace(blob); ImageBox.Show(blob); */ Assert.AreEqual(2, defects.Count); Assert.AreEqual(new IntPoint(130, 10), contour[defects[0].Start]); Assert.AreEqual(new IntPoint(93, 109), contour[defects[0].Point]); Assert.AreEqual(new IntPoint(64, 9), contour[defects[0].End]); Assert.AreEqual(99.549179077148438, defects[0].Depth, 1e-5); Assert.IsFalse(double.IsNaN(defects[0].Depth)); // Assert.AreEqual(9912.9531239366424, defects[0].Area); Assert.AreEqual(new IntPoint(49, 18), contour[defects[1].Start]); Assert.AreEqual(new IntPoint(61, 106), contour[defects[1].Point]); Assert.AreEqual(new IntPoint(18, 127), contour[defects[1].End]); Assert.AreEqual(35.615153852366504, defects[1].Depth, 1e-5); Assert.IsFalse(double.IsNaN(defects[1].Depth)); // Assert.AreEqual(2293.7535682510002, defects[1].Area); }