我試圖編譯這段代碼(最後一個): http://www.aforgenet.com/framework/features/blobs_processing.htmlC#和AForge - 使用未分配的局部變量edgePoints的
但它拋出:使用未分配的局部變量的「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;
什麼問題?我沒有修改源代碼,這樣就可以工作了..
該代碼確實是錯誤的,也許應該告訴網站的所有者。 – svick 2012-02-18 10:04:31