【问题标题】:Converting from EmguCV 3.1 to 3.3 causes code to hang从 EmguCV 3.1 转换为 3.3 会导致代码挂起
【发布时间】:2017-11-23 16:42:50
【问题描述】:

在带有非商业许可证的 EmguCV 3.1.X(从 Nuget 安装)中,我有这个代码,我从 here 获得的并且运行良好:

    public static dynamic GetValue(this UMat mat, int row, int col)
    {
        var value = CreateElement(mat.Depth);
        Marshal.Copy(mat.ToMat(AccessType.Read).DataPointer + (row * mat.Cols + col) * mat.ElementSize, value, 0, 1);
        return value[0];
    }

我现在想切换到 EmguCV 3.3.X 的商业版本(从 Nuget 安装),因此不得不将此代码更改为:

    public static dynamic GetValue(this UMat mat, int row, int col)
    {
        var value = CreateElement(mat.Depth);
        Marshal.Copy(mat.GetMat(AccessType.Read).DataPointer + (row * mat.Cols + col) * mat.ElementSize, value, 0, 1);
        return value[0];
    }

没有明显的原因,这段代码毫无例外地挂起,也没有任何异常: Marshal.Copy(mat.GetMat(AccessType.Read).DataPointer + (row * mat.Cols + col) * mat.ElementSize, value, 0, 1);

我做错了什么还是 EmguCV 中的错误?

【问题讨论】:

  • 库已更改,因此您必须重建您的 c# 项目才能使用新的 dll。通常我只是删除 c# 项目的 bin 文件夹来强制构建所有代码。确保保存您手动放置在 bin 文件夹中的所有文件。当您更改 dll 时,编译器依赖项有时无法识别 dll 更改

标签: c# opencv emgucv


【解决方案1】:

我没有可用的“CreateElement”功能,所以我用下面的代码来测试。应该是类似的。

        UMat u = new UMat(new Size(480, 320), DepthType.Cv8U, 1);
        u.SetTo(new MCvScalar(100));

        byte[] value = new byte[1];
        int row = 100;
        int col = 200;

        using (Mat m = u.GetMat(AccessType.Read))
        {
            IntPtr ptr = m.DataPointer + row * m.Step + col * m.ElementSize;
            Marshal.Copy(ptr, value, 0, 1);
        }

使用 Emgu CV 商业版本 nuget 存储库的 v3.3.0.2824 版本进行测试,并且无需挂起即可工作。如果还是有同样的问题,请上传完整的代码,我去看看。

谢谢。

【讨论】:

    猜你喜欢
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多