how to use boundary box algorithm for people tracking in GUI

1 回表示 (過去 30 日間)
CHE
CHE 2011 年 3 月 8 日
回答済み: Jacob Mathew 2024 年 9 月 25 日
this is my final year project about people tracking in video sequence using GUI.for the Gui.fig, i display 4 axes and have their on push buttons but I'm stuck with the last step to create the rectangle over their head using bounding box(the algorithm method that i used).so, can anyone help me with this method?and how can i create the bounding box frame by frame?
waiting...thank for the helps.

回答 (1 件)

Jacob Mathew
Jacob Mathew 2024 年 9 月 25 日
Hey CHE,
Assuming you have the video and the bounding box coordinates from your model, you can write a script that reads the frame of the video and draw the corresponding bounding box. Then you can write that frame out into another output video. Rinse and repeat over all the frames to get the video with the bounding box. The following code snippet example dmeonstrates this, using the VideoReader and ViderWriter objects:
% Load the video
videoFile = 'InputVideo.mp4'; % Replace with your video file path
videoReader = VideoReader(videoFile);
% Prepare to write the output video
outputVideo = VideoWriter('OutputVideo');
open(outputVideo);
% Example: Dummy bounding box for illustration
% bboxes = [x, y, width, height];
bboxes = [0, 0, 50, 50]; % Replace with your detection results
while hasFrame(videoReader)
% Read the next frame
frame = readFrame(videoReader);
% Updating bboxes to simulate the algorithm tracking person
bboxes(1,1) = bboxes(1,1) +1;
bboxes(1,2) = bboxes(1,2) +1;
% Draw the rectangles on the frame
if ~isempty(bboxes)
frameWithBoxes = insertShape(frame, 'Rectangle', bboxes, 'LineWidth', 3, 'Color', 'yellow');
else
frameWithBoxes = frame; % No detection, keep the frame unchanged
end
% Write the frame to the output video
writeVideo(outputVideo, frameWithBoxes);
end
% Close the video file
close(outputVideo);
The input video is as follows:
The output video is as follows:
You can refer to the documentation of VideoReader & VideoWriter below:
The insertShape function used to draw the bounding box is from the Computer Vision Toolbox and its documentation is as follows:

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by