【发布时间】:2017-01-25 00:21:22
【问题描述】:
我正在尝试使用 AForge.NET 在 C# windows 窗体项目中创建对象检测。
我写了这段代码:
public void DetectCorners()
{
// Load image and create everything you need for drawing
Bitmap image = new Bitmap(@"C:\Users\ssammour\Desktop\Unbenannt.PNG");
originalPicture.ImageLocation = @"C:\Users\ssammour\Desktop\Unbenannt.PNG";
BlobCounter blobCounter = new BlobCounter();
blobCounter.ProcessImage(image);
Graphics g = this.CreateGraphics();
Blob[] blobs = blobCounter.GetObjectsInformation();
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
Pen redPen = new Pen(Color.Red);
for (int i = 0, n = blobs.Length; i < n; i++)
{
List<IntPoint> corners;
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
{
g.DrawPolygon(redPen, ToPointsArray(corners));
image = new Bitmap(image.Width, image.Height, g);
}
}
// Display
newPicture.Image = image;
}
private System.Drawing.Point[] ToPointsArray(List<IntPoint> points)
{
System.Drawing.Point[] array = new System.Drawing.Point[points.Count];
return array;
}
结果总是黑色照片,我不知道为什么。 我用这张照片来尝试代码:
但仍会收到一张黑色照片。 有什么帮助吗?为什么是这样? 如果你能告诉我如何检测图像中的所有对象。
【问题讨论】: