Effacer les filtres
Effacer les filtres

Calculate Centroid of ractangle

9 vues (au cours des 30 derniers jours)
Biswas Lohani V K
Biswas Lohani V K le 3 Juin 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

Réponses (1)

Image Analyst
Image Analyst le 5 Juin 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 commentaire
Biswas Lohani V K
Biswas Lohani V K le 6 Juin 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Computer Vision Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by