How to end "while ~isempty(videoFrame)" loop ?
Show older comments
_if true
f=1;
frame=1;
bbox_w=[0 0 0 0];
l=0;
while ~isempty(videoFrame )
videoFrame = step(videoFileReader);
l=l+1;
bbox = step(faceDetector, videoFrame);
bbox(bbox(:,3)<90,:)=[];
bbox(bbox(:,4)<90,:)=[];
bbox_w=[bbox_w; bbox];
if mod(frame,4)==0
ile=size(bbox,1);
if ile>0
for i=1:ile
figure('Visible','off')
imshow(videoFrame(bbox(i,2):bbox(i,2)+bbox(i,4),bbox(i,1):bbox(i,1)+bbox(i,3),:))
text(10,10,'test')
text(30,30,'test')
title(['Face nr ', num2str(f)])
sb=size(bbox_w);
% b=bbox(i,:);
% a1=bbox_w(sb(1,1),1)
% a2=bbox_w(sb(1,1),2)
% c1=bbox_w(sb(1,1)-1,1)
% c2=bbox_w(sb(1,1)-1,2)
% d1=bbox_w(sb(1,1)-2,1)
% d2=bbox_w(sb(1,1)-2,2)
% e1=bbox_w(sb(1,1)-3,1)
% e2=bbox_w(sb(1,1)-3,2)
if abs(bbox(i,1)-bbox_w(sb(1,1),1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1),2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
%close(gcf)%
f=f+1;
elseif abs(bbox(i,1)-bbox_w(sb(1,1)-1,1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1)-1,2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
f=f+1;
%close(gcf)
elseif abs(bbox(i,1)-bbox_w(sb(1,1)-2,1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1)-2,2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
f=f+1;
elseif abs(bbox(i,1)-bbox_w(sb(1,1)-3,1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1)-3,2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
f=f+1;
end
end
end
end
end_
Answers (1)
Geoff Hayes
on 3 Nov 2017
bfjk12 - are you checking on some condition to decide to prematurely exit the while loop? If so, then just use break to end or exit the while loop.
Looking at your code, you seem to be missing an end which is for the while loop. Perhaps that is what you mean instead. It is best to format your code in such a way that it readable and then you can spot where something might be missing
while ~isempty(videoFrame )
videoFrame = step(videoFileReader);
l=l+1;
bbox = step(faceDetector, videoFrame);
bbox(bbox(:,3)<90,:)=[];
bbox(bbox(:,4)<90,:)=[];
bbox_w=[bbox_w; bbox];
if mod(frame,4)==0
ile=size(bbox,1);
if ile>0
for i=1:ile
figure('Visible','off')
imshow(videoFrame(bbox(i,2):bbox(i,2)+bbox(i,4),bbox(i,1):bbox(i,1)+bbox(i,3),:))
text(10,10,'test')
text(30,30,'test')
title(['Face nr ', num2str(f)])
sb=size(bbox_w);
% b=bbox(i,:);
% a1=bbox_w(sb(1,1),1)
% a2=bbox_w(sb(1,1),2)
% c1=bbox_w(sb(1,1)-1,1)
% c2=bbox_w(sb(1,1)-1,2)
% d1=bbox_w(sb(1,1)-2,1)
% d2=bbox_w(sb(1,1)-2,2)
% e1=bbox_w(sb(1,1)-3,1)
% e2=bbox_w(sb(1,1)-3,2)
if abs(bbox(i,1)-bbox_w(sb(1,1),1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1),2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
%close(gcf)%
f=f+1;
elseif abs(bbox(i,1)-bbox_w(sb(1,1)-1,1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1)-1,2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
f=f+1;
%close(gcf)
elseif abs(bbox(i,1)-bbox_w(sb(1,1)-2,1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1)-2,2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
f=f+1;
elseif abs(bbox(i,1)-bbox_w(sb(1,1)-3,1))>100 && abs(bbox(i,2)-bbox_w(sb(1,1)-3,2))>100
I = imcrop(videoFrame,bbox(i,:));
saveas(gcf,['Face nr ',num2str(f),'.jpg'])
f=f+1;
end
end
end
end
end % <---- this was missing
Categories
Find more on Startup and Shutdown 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!