Help with For Loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey there,
This is apart of a larger code so I've entered a value for total_no_images for ease. I want the user to have an option if the image taken is blurry etc so I've tried to sort it out and researched break/return/continue but not managed to get it quite right. I need the program to take a certain amount of images so don't want it to increment if the first image taken is wrong. Would a switch be better? Any help offered is greatly appreciated!
Thanks!
% Hardware Configuration, set image size
vid = videoinput('winvideo', 1);
% Preview video
start(vid);
preview(vid);
total_no_images=3;
for i = 1:total_no_images
fprintf('Take image %d of %d. Type Yes when ready. \n', i, total_no_images)
decide=input('','s');
if strcmp(decide,'Yes') % Compare two strings
img = getsnapshot(vid); % Capture image
image(img); % Preview image
fprintf('Would you like to retake the image? Yes or No. \n')
accept=input('','s');
if strcmp(accept,'Yes') % Compare two strings
close; % Close preview image
return % If image unacceptable restart
else
filename = ['Image ' num2str(i)]; % Make a file name
imwrite(img, filename, 'bmp'); % Save file as BMP
close; % Close preview image
end
end
end
%Delete and close video preview
close(vid);
closepreview(vid);
delete(vid);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 1 Mär. 2013
i = 1;
while i <= total_no_images
...
if strcmpi(accept, 'Yes')
close
continue;
end
filename = ...
...
i = i + 1;
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!