【问题标题】:why does strel failed in MATLAB Coder为什么 strel 在 MATLAB Coder 中失败
【发布时间】:2020-11-20 02:31:50
【问题描述】:

在 2019b 中使用 MATLAB Coder,以下行:

se = strel('line',20,85);

MATLAB Coder 无法有效描述:

1.所有输入必须是常数。

2.函数调用失败

为什么 Coder 在strel 有困难?

matlab 编码器是否支持strel

【问题讨论】:

    标签: matlab matlab-coder


    【解决方案1】:

    MATLAB Coder 确实支持 strel。我在 R2019b 中尝试了以下简单示例,发现它有效。

    % Function foo.m
    function y = foo
        se = strel('line',20,85);
        y = numel(se.Neighborhood);
    end
    
    % Codegen command in command window
    >> codegen foo -report
    

    从您发布的错误消息来看,您对 strel 的输入似乎不是恒定的,这就是 codegen 失败的原因。请参阅此处文档中有关 C/C++ 代码生成部分的部分:https://www.mathworks.com/help/images/ref/strel.html,其中声明如下:

    使用说明和限制:

    • strel 支持生成 C 代码(需要 MATLAB® Coder™)。如需更多信息,请参阅Code Generation for Image Processing
    • 所有输入参数都必须是编译时常量。
    • 代码生成不支持与 strel 对象关联的方法。
    • 不支持 strel 对象数组。

    根据评论显示 imerode 的示例:

    % Function foo.m
    function y = foo(edgeimg)
        se = strel('line',20,85);
        y = imerode(edgeimg, se.Neighborhood);
    end
    
    % Codegen command in command window
    % The image must be 2D or 3D according to doc
    >> edgeimg = imread('blah.png'); 
    >> codegen foo -args edgeimg -report
    

    【讨论】:

    • 谢谢它解决了 strel 的问题,但是当我在 strel 之后添加 imrode 代码时,MATLAB Coder 遇到了同样的问题:所有输入必须是常量。和函数调用失败。以下行:se1 = strel('line',20,85); zz1 = imerode(edgeimg,se1.Neighborhood);那么 imerode 有什么问题吗?
    • 问题在于您对这些函数的输入。请仔细阅读每个函数的 C/C++ 代码生成部分中的限制。从您共享的错误来看,您的输入似乎不是编译时常量。我已经编辑了我的原始帖子,展示了使用 imerode 的可能方式。
    猜你喜欢
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多