MATLAB: Standing People Detector in Matlab, want to filter out scores below 0.03

computer visionComputer Vision Toolbox

I have tried to create a new box array containing values only from pictures for scores more then 0.03, but it is removing columns in stead of rows so I end up with less then 4 columns with each column part of the the detected picture block, as I understand the 4 rows is the four points of each picture block containing a standing person?
peopleDetector = vision.PeopleDetector;
I = imread('visionteam1.jpg');
[bboxes,scores] = peopleDetector(I);
Dimensions = size(bboxes);
BoxRows = Dimensions(1);
BoxCols = Dimensions(2);
for x =1:BoxRows;
for y = 1:BoxCols;
if scores(y) > 0.04;
NewBox(x,y) = bboxes(x,y);
end
end
end
I = insertObjectAnnotation(I,'rectangle',bboxes,scores);
figure, imshow(I)
title('Detected people and detection scores');

Best Answer

Try this:
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
peopleDetector = vision.PeopleDetector;
rgbImage = imread('visionteam1.jpg');
% Find people.
[boundingBoxes,scores] = peopleDetector(rgbImage)
% Burn boxes into a new image.
rgbImage2 = insertObjectAnnotation(rgbImage,'rectangle',boundingBoxes,scores);
% Display image with boxes burned into it.

subplot(1, 2, 1);
imshow(rgbImage2);
title('All Detected Boxes with All Scores', 'FontSize', fontSize);
% Extract only those boxes with scores > 0.03
rowsToExtract = scores > 0.03
goodBoxes = boundingBoxes(rowsToExtract, :)
scores = scores(rowsToExtract)
% Burn only "good" boxes into a new image.
rgbImage3 = insertObjectAnnotation(rgbImage,'rectangle',goodBoxes,scores);
% Display image with boxes burned into it.
subplot(1, 2, 2);
imshow(rgbImage3);
title('People with Detection Scores > 0.3', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
uiwait(msgbox('Done!'))
Note how there are only 3 (instead of 4) detected people on the right image.