HDL Coder Error. Undefined function or variable. The first assignment to a local variable determines its class.
6 views (last 30 days)
Show older comments
good day. im trying to convert my code to verilog using hdl coder but i encounter multiple errors with the same description, "Undefined function or variable. The first assignment to a local variable determines its class." can anyone help me resolve my problem? btw my input is Gen1 which is supposed to be the image captured by our camera.thank you
here is my code
function [ Y ] = Try( Gen1 )
[rows, columns, numberOfColorBands] = size(Gen1)
if numberOfColorBands > 1
grayG1 = Gen1(:, :, 2);
end
BinG1 = grayG1 > 200;
CanEdG1=imcomplement(BinG1);
[nonZeroRows nonZeroColumns] = find(CanEdG1);
topRow = min(nonZeroRows(:));
bottomRow = max(nonZeroRows(:));
leftColumn = min(nonZeroColumns(:));
rightColumn = max(nonZeroColumns(:));
CrpdG1 = CanEdG1 (topRow:bottomRow,leftColumn:rightColumn);
mPadded = padarray(CrpdG1, [125, 125]);
midx=ceil((size(mPadded,1)+1)/2);
midy=ceil((size(mPadded,2)+1)/2);
K=50;
x2=zeros([size(mPadded,1) size(mPadded,2)]);
y2=zeros([size(mPadded,1) size(mPadded,2)]);
for i=1:size(mPadded,1)
x=i-midx-K;
for j=1:size(mPadded,2)
%Cartesian to Polar co-ordinates
[theta1,rho1]=cart2pol(x,j-midy+K);
phi=theta1+(rho1/K);
%Polar to Cartesian co-ordinates
[l,m]=pol2cart(phi,rho1);
x2(i,j)=ceil(l)+midx;
y2(i,j)=ceil(m)+midy;
end
end
%The result may produce value lesser than 1 or greater than the image size.
x2=max(x2,1);
x2=min(x2,size(mPadded,1));
y2=max(y2,1);
y2=min(y2,size(mPadded,2));
for i=1:size(mPadded,1)
for j=1:size(mPadded,2)
Y(i,j,:)= mPadded (x2(i,j),y2(i,j),:);
end
end
end
0 Comments
Answers (1)
Tim McBrayer
on 25 Sep 2015
What variables does the issue occur with? By inspection you do not define grayG1 if numberOfColorBands <= 1. Running the code in MATLAB interactively also shows that it fails due to this reason.
HDL Coder needs code that fits the expected idiom for HDL translation. One immediate issue is that you will probably never want to transfer an entire image in a single input variable; FPGAs simply do not have that many IO pins, for any decent sized image. The typical way of working with images is to stream the image in pixel by pixel, storing it in a persistent variable if desired.
In addition, functions like 'imcomplement' aren't supported for HDL code generation. The full list of HDL-supported functions are in the documentation:
web(fullfile(docroot, 'hdlcoder/ug/functions-supported-for-hdl-code-generation-alphabetical-list.html'))
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!