繁体   English   中英

C#和AForge-使用未分配的局部变量edgePoints

[英]C# and AForge - Use of unassigned local variable edgePoints

我正在尝试编译此代码(最后一个): 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;

有什么问题? 我没有修改源代码,所以一切正常。

您需要-为其分配一个值:

List<IntPoint> leftPoints, rightPoints, edgePoints;
edgePoints = new List<IntPoint>();

在该实例上调用方法之前。

您的leftPointsrightPoints可能由初始化

blobCounter.GetBlobsLeftAndRightEdges(blob, out leftPoints, out rightPoints);

调用(请注意out关键字),但是edgePoints不是-您需要自己执行此操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM