Clear Filters
Clear Filters

Measuring the distance between Bounding box and change their colors for certain condition

2 views (last 30 days)
Hi guys
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
vidReader = VideoReader('vn_045_00.avi');
vidPlayer = vision.DeployableVideoPlayer;
i = 1;
results = struct('Boxes',[],'Scores',[]);
I = readFrame(vidReader);
fps = 0;
avgfps = [];
[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));
i = i+1;
results = struct2table(results);

Answers (0)

Community Treasure Hunt

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

Start Hunting!