MatLab Facial Detection Assistance
Show older comments
Greetings,
I have been trying to get some of the code in Doug Hull's video blog to work on a directory of images. Basically, I want to perform the upper-body crop trick to each image in the directory...but I am running into an 'index out of bounds error' anywhere I use the loop index to reference the bbox matrix. It keeps saying the size of the bbox_body is [1,4] and then it tries to access [2:].
Any assistance would be appreciated, I am kind of a novice to MatLab in general.
CODE:
class="code" dirListing = dir('*.jpg');
for d=1:length(dirListing) if ~dirListing(1).isdir
img = imread(dirListing(d).name);
faceDetector = vision.CascadeObjectDetector();
bodyDetector = vision.CascadeObjectDetector('UpperBody');
bodyDetector.MinSize = [60 60];
bodyDetector.ScaleFactor = 1.05;
bbox_body = step(bodyDetector, img);
shapeInserter = vision.ShapeInserter('BorderColor', 'Custom', 'CustomBorderColor', [0 255 0]);
bbox_face = zeros(size(bbox_body));
for index=1:length(bbox_body)
ImgCrop = imcrop(img, bbox_body(index,:));
bbox = step(faceDetector, ImgCrop);
bbox_face(index,:) = bbox + [bbox_body(index,1:2)-1 0 0];
end
ImgFaces2 = step(shapeInserter, img, int32(bbox_face));
figure, imshow(ImgFaces2), title('With Upper Body');
end
end
</pre>
Answers (1)
Dima Lisin
on 24 Dec 2013
0 votes
It may be the case that the detector is not finding any objects in your image. You should check bbox for being empty before indexing into it.
Categories
Find more on Image Processing Toolbox 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!