Currently I try to run example Detect and Track Multiple Face. When I try to crop the images of detected face as follow:
.....
while keepRunning
.....
displayFrame = insertMarker(displayFrame, tracker.Points);
for I=1:size(bboxes,1)
J = imcrop(displayFrame, tracker.Bboxes(I, :));
imshow(J);
cropfile = sprint('crop %d.jpg, I);
imwrite(J, cropfile, 'jpg');
end
.....
However when the subject is out of view, there will be an error regarding 'index is out of bounds because size(tracker.Bboxes)=[0,4].
When you are no more in frame
then bounding box is empty ;you should check it before looping
if ~isempty(bboxes)
for I=1:size(bboxes,1)
J = imcrop(displayFrame, tracker.Bboxes(I, :));
imshow(J);
cropfile = strcat('crop', num2str(I));
cropfilefull =[cropfile,'.jpg'];
imwrite(J, cropfilefull, 'jpg');
end
end
it worked for me