Help please. Error message: statement can't be reached <LINE 42>
Show older comments
code is
a = arduino;
for i=1:3
writeDigitalPin(a,10,1)
pause(1)
writeDigitalPin(a,10,0)
pause(1)
end
cam = webcam;
preview(cam)
pause(5)
closePreview(cam)
while 1
input1 = readDigitalPin(a,2);
input2 = readDigitalPin(a,4);
input3 = readDigitalPin(a,6);
if input1 == 1
live = snapshot(cam);
imshow(live)
elseif input2 == 1
ref=snapshot(cam);
imshow(ref)
pause(5)
live=snapshot(cam);
imshow(live)
elseif input3 == 1
ref=snapshot(cam);
while 1
pause(15)
live = snapshot(cam);
imshow(live)
end
end
end
ref1 = imread('ref.jpg');
ref2 = imresize(ref1,[300 300]);
imwrite(ref2,'ref3.jpg');
live1 = imread('live.jpg');
live2 = imresize(live1,[300 300]);
imwrite(live2,'live3.jpg');
A=imread('ref3.jpg');
M=imread('live3.jpg');
A=rgb2gray(A);
M=rgb2gray(M);
figure,imshow(A);
title('after gray conversion A');
figure,imshow(M);
title('after gray conversion M');
J=wiener2(A,[5 5]);
title('image after wiener filtering A');
figure,imshow(J);
J1=wiener2(M,[5 5]);
title('image after wiener filtering M');
figure,imshow(J1);
BW1=edge(J,'canny');
figure,imshow(BW1);
title('image after edge detection A');
BW2=edge(J1,'canny');
figure,imshow(BW2);
title('image after edge detection M');
matched_points = 0;
matched_points1 = 0;
white_points = 0;
black_points = 0;
x=0;
y=0;
l=0;
m=0;
for a = 1:1:300
for b = 1:1:300
if(BW1(a,b)==1)
white_points1 = white_points+1;
else
black_points = black_points+1;
end
end
end
for i = 1:1:300
for j = 1:1:300
if(BW1(i,j)==BW2(i,j))
matched_points = matched_points+1;
else
matched_points1 = matched_points1+1;
end
end
end
total_points = white_points + black_points;
total_matched_percentage = (matched_points/total_points)*100;
display(The_images_match_by_)
display(total_matched_percentage)
if(total_matched_percentage >= 85)
time=15;
display(Red_light_ON_time_)
display(time)
writeDigitalPin(a,12,1)
pause(15)
elseif(total_matched_percentage >= 50 && total_matched_percentage <= 85)
time=30;
display(Green_light_ON_time_)
display(time)
writeDigitalPin(a,10,1)
pause(30)
else
time=45;
display(Green_light_ON_time_)
display(time)
writeDigitalPin(a,10,1)
pause(45)
end
Answers (1)
The problem is your while loop:
while 1
is always true, and you do not have any break statement inside the loop. So the loop will run forever, and the statements following the loop
ref1 = imread('ref.jpg');
will never run. MATLAB's code analysis tool recognizes this and gives that warning in the editor.
Categories
Find more on Track Objects and Estimate Motion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!