MATLAB: Problem with bounding boxes.

image processingImage Processing Toolbox

faceDetector = vision.CascadeObjectDetector();
lframe=vida(curr-9).cdata;
bbox = step(faceDetector, lframe);
%some extra coding that reset lframe
lframelabel = regionprops(lframe,'BoundingBox');
boxes = cat(1, lframelabel.BoundingBox);
[m,~]=size(boxes);
for idx=1:m
if (bboxOverlapRatio(boxes(idx,:),bbox) > 0)
play(player);
end
end
I have visually verified that the 2 bounding boxes overlaps. Yet the test condition does not trigger therefore my player does not play. Can anyone help?

Best Answer

You're not passing in a bounding box. boxes(idx,:) is a bounding box for idx = 1, 5, 9, etc. (every 4) but not for 2,3,4,6,7,8, etc. Just look at what boxes is. It's [x1,y1,w1,h1,x2,y2,w2,h2,x3,y3,w3,h3,.....] So when idx = 3, say, boxes(idx,:) = w1. Since boxes is a 1-D array, the ,: does nothing - it's just looking at the idx value. You'd have to skip by 4 and take just 3 of them:
for idx = 1 : 4 : m
thisBoundingBox = boxes(idx:idx+3);
if (bboxOverlapRatio(thisBoundingBox, bbox) > 0)
or better yet , don't concatenate the boxes and loop over them at all , but just loop over the regions:
for r = 1 : length(lframelabel)
thisBoundingBox = lframelabel(r).BoundingBox;
if (bboxOverlapRatio(thisBoundingBox, bbox) > 0)
Related Question