Problem with bounding boxes.

3 visualizzazioni (ultimi 30 giorni)
Daniel N
Daniel N il 3 Ago 2015
Commentato: Daniel N il 4 Ago 2015
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?

Risposta accettata

Image Analyst
Image Analyst il 3 Ago 2015
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)
  3 Commenti
Image Analyst
Image Analyst il 4 Ago 2015
I don't have that toolbox. I suggest you hard code in 1-by-4 arrays for the boxes and pass that in to bboxOverlapRatio() and see if it's working for known coordinates. For your current case put these lines in before that call:
thisBoundingBox
bbox
trueOrFalse = bboxOverlapRatio(thisBoundingBox, bbox)
figure
rectangle('Position', thisBoundingBox);
hold on;
rectangle('Position', bbox);
Then you can see, both in numbers in the command window, and in a new figure, whether they overlap or not. Don't put semicolons at the end of the lines to make sure they printout to the command window.
Daniel N
Daniel N il 4 Ago 2015
Ahh... Found the problem. The bbox was same as the boundingbox that I cat it before - it has more than 1 row. Managed to solve the problem by removing the semi-colon and double checking the matrices only to realise that. Thanks.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by