C#和AForge-使用未分配的局部变量edgePoints
本文关键字:分配 局部变量 edgePoints AForge- | 更新日期: 2023-09-27 18:24:58
我正在尝试编译以下代码(最后一个):http://www.aforgenet.com/framework/features/blobs_processing.html
但它抛出:使用未分配的局部变量"edgePoints"。。
这是代码:
BlobCounter blobCounter = new BlobCounter();
blobCounter.ProcessImage(image23);
Blob[] blobs = blobCounter.GetObjectsInformation();
GrahamConvexHull hullFinder = new GrahamConvexHull();
BitmapData data = image23.LockBits(new Rectangle(0, 0, image23.Width, image23.Height), ImageLockMode.ReadWrite, image23.PixelFormat);
foreach (Blob blob in blobs)
{
List<IntPoint> leftPoints, rightPoints, edgePoints;
blobCounter.GetBlobsLeftAndRightEdges(blob, out leftPoints, out rightPoints);
edgePoints.AddRange(leftPoints);
edgePoints.AddRange(rightPoints);
List<IntPoint> hull = hullFinder.FindHull(edgePoints);
Drawing.Polygon(data, hull, Color.Red);
}
image23.UnlockBits(data);
这是他遇到的问题:
edgePoints.AddRange(leftPoints);
我绑定为edgePoints分配Null,但失败了:
List<IntPoint> leftPoints, rightPoints, edgePoints= null;
出了什么问题我没有修改源代码,所以一切都应该正常。。
您需要给它赋值:
List<IntPoint> leftPoints, rightPoints, edgePoints;
edgePoints = new List<IntPoint>();
在对该实例调用方法之前。
您的leftPoints
和rightPoints
可能已由初始化
blobCounter.GetBlobsLeftAndRightEdges(blob, out leftPoints, out rightPoints);
call(注意out
关键字),但edgePoints
不是-您需要自己完成。