필터 지우기
필터 지우기

Calculate Centroid of ractangle

조회 수: 4 (최근 30일)
Biswas Lohani V K
Biswas Lohani V K 2016년 6월 3일
댓글: Biswas Lohani V K 2016년 6월 6일
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
Biswas Lohani V K 2016년 6월 6일
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 Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by