error HDL Coder "Index expression out of bounds. Attempted to access element 2. The valid range is 1-1."

1 vue (au cours des 30 derniers jours)
Matlab Code (also attached)
function [npixnoir,surf_obj,D_euc,moy_H,lines,surf_obj_rouge] = traitement(im)
coder.extrinsic('imread');
coder.extrinsic('imfill');
coder.extrinsic('istrel');
coder.extrinsic('imshow');
coder.extrinsic('imopen');
coder.extrinsic('imclearborder');
coder.extrinsic('strel');
coder.extrinsic('imerode');
coder.extrinsic('bwlabel');
coder.extrinsic('regionprops');
coder.extrinsic('imclose');
coder.extrinsic('houghlines');
coder.extrinsic('houghpeaks');
coder.extrinsic('subplot');
im= imread('E:\work\40.jpg');
r=im(:,:,1);
g=im(:,:,2);
b=im(:,:,3);
I1 = (r-g)>40 &(r-b)>40;
maskFound=(I1) ;
se = strel('disk',2);
maskOpen = imopen(maskFound,se);
se2 = strel('disk',20);
maskClose = imclose(maskOpen,se2);
BWdfill = imfill(maskClose, 'holes');
BWnobord = imclearborder(BWdfill, 4);
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
segmentedIm = imerode(BWfinal,seD);
[labeledImage numberOfBlobs] = bwlabel(segmentedIm, 4);
blobMeasurements = regionprops(labeledImage, 'BoundingBox','Area');
subplot(2, 2, 4);imshow(im);
for k = 1 : numberOfBlobs
hold on
boundingBox = blobMeasurements(k).BoundingBox; % Get box.
x1 = boundingBox(1);
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
%Nombre de pixels noirs
npixnoir=sum(~k(:));
% Surface des objets blancs
surf_obj=bwarea(k);
%Distance quasi-euclidienne maximale
D_euc = bwdist(k);
%Calculer Moyenne de la matrice de transformé de Hough
[H,theta,rho] = hough(k);
moy_H=mean(H);
%Longueur maximale de droites existées dans la forme
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(k,theta,rho,P,'FillGap',5,'MinLength',7);
surf_obj_rouge=bwarea(k);
rectangle('Position',blobMeasurements(k).BoundingBox,'EdgeColor','g','LineWidth',2 );
end
subplot(2, 2, 1);
imshow(im);title('Image original');
subplot(2, 2, 2);
imshow(I1);title('pixelCandidates');
subplot(2, 2, 3);
imshow(segmentedIm);title('segmentedIm');
end
OUTPUT
I try to get the VHDL code corresponding to my simulation on MATLAB with HDL coder app, but I get a first error at the line 21 when I build the MATLAB code on the HDL coder app
Here error msg
%

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Mai 2016
You cannot use imread() in HDL. HDL has no I/O system.
When you are building for HDL, you have to assign to each variable before it is used as the output of a call. The assignment will determine the size and data type of the variable, which will be important for determining how many memory cells to allocate in the HDL. The maximum size of variables must be strictly defined because there is no dynamic memory allocation in HDL.
You should be recoding your algorithm to take as input a vector of values of fixed size (or at least maximum fixed size if the sizes are passed in). You can then reshape() to array for processing. The vector form is necessary because you need to cut down to a small number of I/O pins because FPGA do not have large pin-outs. Remember, one pin for every bit for every value that is to be input simultaneously, so you want to have a narrow bus (at high speed) to transfer your image array.
  4 commentaires
landolsi marwa
landolsi marwa le 16 Mai 2016
please r, g, b, I1 should be declared as or not necessary
Walter Roberson
Walter Roberson le 16 Mai 2016
Anything like r that is extracted with fixed indices directly from a variable of known size does not itself have to have its size declared:
Any variable that is assigned the result of calling a MATLAB routine must first have its size and type declared.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by