Calculate Centroid of ractangle

10 次查看(过去 30 天)
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

回答(1 个)

Image Analyst
Image Analyst 2016-6-5
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 个评论
Biswas Lohani V K
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by