HDL Coder Error. Undefined function or variable. The first assignment to a local variable determines its class.

4 views (last 30 days)
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

Answers (1)

Tim McBrayer
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
Princess Aldovino
Princess Aldovino on 25 Sep 2015
Edited: Princess Aldovino on 26 Sep 2015
unfortunately im getting an error when i type it in matlab so i googled it and this is what i found.
it only says that imcomplement "Does not support int64 and uint64 data types" but my input is only uint8. Now i am faced with the same error but the error only applies to my output variable. How can i define my output as a logical? thanks
we bought a cam from terasic and it comes with a code for integration but unfortunately we still cant understand the flow of the code thus we dont really know how the data is streamed for processing

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!