isolating bounding boxes from a video using detector

조회 수: 2 (최근 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 CenterFile Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by