不能在 C# 中将 'FindContours' 与 EmguCV 一起使用

Can not use 'FindContours' with EmguCV in C#

我试图在我的二进制图像中找到最大的对象。我曾经在第 52 行编码 here 但我在 FindContours 上遇到了错误,如下所示。

我的代码有什么问题?还有其他方法可以找到二值图像中面积最大的对象吗?

你升级到3.0了吗?这会导致问题,而且这是一个相当普遍的现象(在这里查看我的回答:Emgu CV 3 findContours and hierarchy parameter of type Vec4i equivalent?)。基本上,据我所知,Emgu 团队尚未将所有功能迁移到最新版本,因此需要重做一些在 2.X 中有效的功能。

如果您想使用该功能,可以直接调用 FindContours 方法:

/// <summary>
/// Find contours using the specific memory storage
/// </summary>
/// <param name="method">The type of approximation method</param>
/// <param name="type">The retrieval type</param>
/// <param name="stor">The storage used by the sequences</param>
/// <returns>
/// Contour if there is any;
/// null if no contour is found
/// </returns>
public static VectorOfVectorOfPoint FindContours(this Image<Gray, byte> image, ChainApproxMethod method = ChainApproxMethod.ChainApproxSimple,
    Emgu.CV.CvEnum.RetrType type = RetrType.List) {
    // Check that all parameters are valid.
    VectorOfVectorOfPoint result = new VectorOfVectorOfPoint();

    if (method == Emgu.CV.CvEnum.ChainApproxMethod.ChainCode) {
        throw new ColsaNotImplementedException("Chain Code not implemented, sorry try again later");
    }

    CvInvoke.FindContours(image, result, null, type, method);
    return result;
}