フィルターのクリア

isolating bounding boxes from a video using detector

1 回表示 (過去 30 日間)
Shirshak
Shirshak 2023 年 1 月 27 日
編集済み: Ajay Gajulapally 2023 年 3 月 2 日
Hi mathworks team,
I am trying to isolate bounding boxes values from frames of video using trained detector but it gives this error ''Index exceeds the number of array elements. Index must not exceed 1.''
here is code
% import the video file
obj = VideoReader('test2video.mp4');
vid = read(obj);
% read the total number of frames
frames = obj.NumberOfFrames;
% file format of the frames to be saved in
ST ='.jpg';
a = cell(1, frames+1);
% reading and writing the frames
for x = 1 : frames
% % converting integer to string
Sx = num2str(x);
%
% % concatenating 2 strings
Strc = strcat(Sx, ST);
Vid = vid(:, :, :, x);
cd frames;
% %
% % % exporting the frames
imwrite(Vid, Strc);
cd ..
for i = 1:x
m = imread(['C:\Users\shirs\Documents\SURF\SSDVOBJECT\frames\' Sx(i) '.jpg']);
[bboxes, scores] = detect(detector, m);
a{i} = bboxes;
figure
imshow(m)
end
end
  3 件のコメント
Shirshak
Shirshak 2023 年 1 月 27 日
No .. this line is for saving it in one folder..then from there i try to run a loop and isolate the bounding boxes.
any answers ?
Shirshak
Shirshak 2023 年 2 月 3 日
hi team, did you get any answers on this

サインインしてコメントする。

回答 (1 件)

Ajay Gajulapally
Ajay Gajulapally 2023 年 3 月 2 日
編集済み: Ajay Gajulapally 2023 年 3 月 2 日
Hi Shirshak,
As per my understanding, you want to isolate the bounding boxes of detected objects in a video frame by frame. Kindly check the way you use your second for loop. The modified code can go as:
  1. Importing the video file and reading the frames
% import the video file
obj = VideoReader('________'); % use the video file here
vid = read(obj);
% read the total number of frames
frames = obj.NumFrames;
2. Writing the frames to a required path.
% file format of the frames to be saved in
ST ='.jpg';
% reading and writing the frames
for x = 1 : frames
% % converting integer to string
Sx = num2str(x);
%
% % concatenating 2 strings
Strc = strcat(Sx, ST);
Vid = vid(:, :, :, x);
cd frames;
% % % exporting the frames
imwrite(Vid, Strc);
cd ..
end
3. Load your trained detector and save the bounding boxes to a variable.
detector = yolov3ObjectDetector("tiny-yolov3-coco"); % load your trained detector here
a = cell(1,frames+1);
for i = 1:frames
z = "PATH_NAME\frames\"+string(i)+".jpg";
m = imread(z);
[bboxes, scores] = detect(detector, m);
a{1,i} = bboxes;
annotatedImage = insertShape(m, 'Rectangle', a{i});
figure
imshow(annotatedImage);
end
Hope this helps!

カテゴリ

Help Center および File ExchangeTracking and Motion Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by