Error: Attempt to reference field of non-structure array
Mostrar comentarios más antiguos
The code:
close all;clear all;clc;
a=arduino('COM14');
a.pinMode(2,'OUTPUT');
a.pinMode(3,'OUTPUT');
a.pinMode(4,'OUTPUT');
a.pinMode(5,'OUTPUT');
a.pinMode(9,'OUTPUT');
a.pinMode(10,'OUTPUT');
vid=videoinput('winvideo',1,'YUY2_160X120');
set(vid,'TriggerRepeat',Inf);
vid.returnedcolorspace='rgb';
vid.FrameGrabInterval=2;
start(vid) %start the video aquisition here
while(vid.FramesAcquired<=200)
data1=getdata(vid,1);
C=imrotate(data1,90);
data=imcomplement(C);
% Now to track yellow objects in real time
% we have to subtract the yellow component
% from the grayscale image to extract the yellow components in the image.
diff_im = imsubtract(data(:,:,3), rgb2gray(data));
diff_im=medfilt2(diff_im,[1 2]); % Use a median filter to filter out noise
diff_im=im2bw(diff_im,0.26); % Convert the resulting grayscale image into a binary image.
diff_im=bwareaopen(diff_im,50); % Remove all those pixels less than 50px
bw=bwlabel(diff_im,8); % Label all the connected components in the image.
% This is where the image blob analysis occur.
% Get a set of properties for each labeled region.
stats=regionprops(bw,'BoundingBox','Centroid');
% Display the image
imshow(C)
hold on
% This is a loop to bound the yellow objects in a rectangular box and
% along with its center coordinate
for object=1:length(stats)
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','Y','LineWidth',2);
plot(bc(1),bc(2),'-m+');
a=text(bc(1)+15,bc(2), strcat('X:', num2str(round(bc(1))), 'Y:', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
X=num2str(round(bc(1)));
Y=num2str(round(bc(2)));
if (X>61);
a.digitalWrite(10, 1);
a.digitalWrite(4, 1);
a.digitalWrite(5, 0);
end
if (X<59);
a.digitalWrite(10, 1);
a.digitalWrite(4, 0);
a.digitalWrite(5, 1);
end
if (X<=61);
a.digitalWrite(9, 0);
a.digitalWrite(10, 0);
end
if (X>=59);
a.digitalWrite(9, 0);
a.digitalWrite(10, 0);
end
end
hold off
end
stop(vid); % Video acquisition is halted.
flushdata(vid); % Removes all the processed image strored in RAM.
clear all
The output:
Attempt to reference field of non-structure array
Error in filename (line 51)
a.digitalWrite(10, 1);
What I am trying to achieve here is to make the arduino gives the output when "if" conditions are met.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Arduino Hardware en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!