Measuring the width and hight for smallest Bounding Boxes of detected objects
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Abdussalam Elhanashi
il 20 Gen 2020
Commentato: Abdussalam Elhanashi
il 19 Mag 2020
Hi guys,
Kindly looking for Measuring the width and highth for the smallest Bounding Boxex of detected object in the following code
load('Detector.mat');
vidReader = VideoReader('vs_002_00.avi');
vidPlayer = vision.DeployableVideoPlayer;
i = 1;
results = struct('Boxes',[],'Scores',[]);
while(hasFrame(vidReader))
I = readFrame(vidReader);
% PROCESS
[bboxes, scores, label] = detect(detector,I,'MiniBatchSize', 128);
% Select strongest detection
% New - Find those bounding boxes that surpassed a threshold
T = 0.5; % Define threshold here
idx = scores >= T;
% Retrieve those scores that surpassed the threshold
s = scores(idx);
% Do the same for the labels as well
lbl = label(idx);
bboxes = bboxes(idx, :); % This logic doesn't change
for ii = 1 : size(bboxes, 1)
annotation = sprintf('%s: (Confidence = %f)', lbl(ii), s(ii)); % Change
I = insertObjectAnnotation(I, 'rectangle', bboxes(ii,:), annotation); % New - Choose the right box
end
boundingBoxArea = prod(boundingBox(3:4));
step(vidPlayer,I);
i = i+1;
end
results = struct2table(results);
release(vidPlayer);
2 Commenti
Guillaume
il 20 Gen 2020
Is the variable boundingBox defined somewhere in your code? It's not clear what its relationship is to bboxes.
You haven't actually asked a question, so I'm not exactly sure what you want.
Risposta accettata
Guillaume
il 20 Gen 2020
Modificato: Guillaume
il 20 Gen 2020
For the area of Bounding Boxes what is the unit used?
pixel squared. If you want to convert to physical unit (e.g. ) you need to know the scale of your images.
You still haven't explained where boundingBox come from. As far as I can tell, your code uses the variable before defining it.
Using the bboxes variable, this is how you would find the bounding with the smallest area:
bboxes = bboxes(idx, :); % This line from your code. Unchanged
bboxesarea = prod(bboxes(:, 3:4), 2); %calculate the area of all the bounding boxes by multiplying height by width. produces a column vector
[smallestarea, boxindex] = min(bboxarea); %get index of smallest bounding box (and area if you need it).
%optional: label the bounding box in red
I = insertObjectAnnotation(I, 'rectangle', bboxes(boxindex,:), sprintf('%s: (Confidence = %f), Area (pixel^2) = %d', lbl(boxindex), s(boxindex), smallestarea), 'Color', 'red');
3 Commenti
Più risposte (1)
Image Analyst
il 20 Gen 2020
If you want boxes aligned with the image edges, then use regionprops() and ask for 'BoundingBox'.
If you want boxes at any angle, use bwferet().
Or you could use John's program. https://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of-minimal-bounding-objects
16 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!