Clear Filters
Clear Filters

Calculate Centroid of ractangle

9 views (last 30 days)
Biswas Lohani V K
Biswas Lohani V K on 3 Jun 2016
How can i modify this code to calculate the centroid of ractangular box as shown in the figure below.
peopleDetector = vision.PeopleDetector;
I = imread('detectman.jpg');
bboxes = step(peopleDetector, I);
people = insertObjectAnnotation(I, 'rectangle', bboxes, 'people');
figure, imshow(people)
I appreciate your feedaback and suggestion.
Thank you,
Regards,
Biswas

Answers (1)

Image Analyst
Image Analyst on 5 Jun 2016
bboxes is probably in the form [left, top, width, height] like rectangles usually are in MATLAB code. So the centroid is
xCentroid = bboxes(1) + bboxes(3)/2;
yCentroid = bboxes(2) + bboxes(4)/2;
  1 Comment
Biswas Lohani V K
Biswas Lohani V K on 6 Jun 2016
Yes i implemented it in a recorded video.now i want to store this centroid in an array so that i can plot a graph from that values.
videoFReader = vision.VideoFileReader('new.mp4');
videoPlayer = vision.VideoPlayer;
time=1;
len = 250;
xCentroid = zeros(len,1);
yCentroid = zeros(len,1);
while ~isDone(videoFReader)
peopleDetector = vision.PeopleDetector;
frame = step(videoFReader);
bboxes = step(peopleDetector, frame);
people = insertObjectAnnotation(frame, 'rectangle', bboxes, 'people');
hold on
for object = 1:length(bboxes)
time = time + 1;t = 2:time;
xCentroid(time+1) = bboxes(1) + bboxes(3)/2;
yCentroid(time+1) = bboxes(2) + bboxes(4)/2;
end
hold off
imshow(people);
step(videoPlayer,frame);
end
release(videoFReader);
release(videoPlayer);
i have tried with this code but i have got wrong value.
so could you please have a look on code so i that i can solve this problem.
Thank you.

Sign in to comment.

Categories

Find more on Computer Vision Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!