【发布时间】: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
在 2019b 中使用 MATLAB Coder,以下行:
se = strel('line',20,85);
MATLAB Coder 无法有效描述:
1.所有输入必须是常数。
2.函数调用失败
为什么 Coder 在strel 有困难?
matlab 编码器是否支持strel?
【问题讨论】:
标签: matlab matlab-coder
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
【讨论】: