Measuring the width and hight for smallest Bounding Boxes of detected objects

조회 수: 11 (최근 30일)
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
Guillaume
Guillaume 2020년 1월 20일
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.
Abdussalam Elhanashi
Abdussalam Elhanashi 2020년 1월 20일
Guillaume yes what i mean by bboxes is the boundingBox that are used for object detection in fact there are many objects detected in the video and i want to measure the hight and width for the smallest bboxes of these detected objects in this code

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2020년 1월 20일
편집: Guillaume 2020년 1월 20일
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
Guillaume
Guillaume 2020년 1월 20일
bboxesarea contain the area of all the bounding boxes that you've kept.
Abdussalam Elhanashi
Abdussalam Elhanashi 2020년 1월 20일
Hi Guillaume
It gives only the last detected bounding box from the video but not history for all bounding boxes detected with pixel squared measurment
I need the whole history of all detected boxes with pixel squaredCapture1.PNG
i attached image captured from Matlab

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 1월 20일
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().
  댓글 수: 16
Image Analyst
Image Analyst 2020년 1월 23일
Like I said, yes. Make sure you understand my last comment though.
Abdussalam Elhanashi
Abdussalam Elhanashi 2020년 5월 19일
@ImageAnalyst
I am using yolov2 for object detection and i want to implement the following issue for my code
i want to make a condition in the time when two or more bounding boxes are near each other for instance 6 feet or less , the color of bounding box need to change its color from green to red. And once these bounding boxes of detected objects get away from each other more than 6 feet the color of these bounding boxes change back from red to green color
6 feet from bounding box to another
Herein my code
close all
clc
load('detectorYolo2.mat');
vidReader = VideoReader('vn_045_00.avi');
vidPlayer = vision.DeployableVideoPlayer;
i = 1;
results = struct('Boxes',[],'Scores',[]);
while(hasFrame(vidReader))
% GET DATA
I = readFrame(vidReader);
fps = 0;
avgfps = [];
tic;
% PROCESS
[bboxes, scores,label] = detect(detectorYolo2,I,'Threshold',0.4);
newt = toc;
% fps
fps = .9*fps + .1*(1/newt);
avgfps = [avgfps, fps]; %#ok<AGROW>
% Select strongest detection
T = 0.0; % 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
I = insertText(I , [1, 1], sprintf('FPS %2.2f', fps));
end
step(vidPlayer,I);
i = i+1;
end
results = struct2table(results);
release(vidPlayer);

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by