【发布时间】:2012-02-18 09:59:23
【问题描述】:
我正在尝试编译这段代码(最后一个): 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);
我绑定了将 Null 分配给 edgePoints 但它失败了:
List<IntPoint> leftPoints, rightPoints, edgePoints= null;
有什么问题?我没有修改源代码,所以一切都应该正常..
【问题讨论】:
-
该代码确实是错误的,也许应该告诉网站所有者。