简体   繁体   English

无法在C#中的EmguCV中使用'FindContours'

[英]Can not use 'FindContours' with EmguCV in C#

I am trying to find biggest object in my binary image. 我正在尝试在二进制图像中找到最大的对象。 I used to code here in line 52 but I got the error on FindContours shown below. 我以前在这里在第52行进行编码,但是在如下所示的FindContours上遇到了错误。

What is wrong in my code? 我的代码有什么问题? and Is there an other way to find the object has biggest area in binary image? 还有其他方法可以找到二进制图像中具有最大面积的对象吗?

在此处输入图片说明

Did you upgrade to 3.0? 您是否升级到3.0? That would cause the issue, and it's a fairly common occurrence (see my answer here: Emgu CV 3 findContours and hierarchy parameter of type Vec4i equivalent? ). 这将导致问题,并且这是相当普遍的情况(请在此处查看我的答案: Emgu CV 3 findContours和等同于Vec4i类型的层次结构参数? )。 Basically, from what I have seen, the Emgu team has not yet migrated all the functionality to the newest versions, so some things that worked in 2.X will need to be redone. 基本上,从我所看到的来看,Emgu团队尚未将所有功能迁移到最新版本,因此需要重做在2.X中可用的某些功能。

If you want to use that functionality, you can directly invoke the FindContours method: 如果要使用该功能,可以直接调用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;
}

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

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