Calculate Centroid of ractangle

3 visualizaciones (últimos 30 días)
Biswas Lohani V K
Biswas Lohani V K el 3 de Jun. de 2016
Comentada: Biswas Lohani V K el 6 de Jun. de 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

Respuestas (1)

Image Analyst
Image Analyst el 5 de Jun. de 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 comentario
Biswas Lohani V K
Biswas Lohani V K el 6 de Jun. de 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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by