Borrar filtros
Borrar filtros

isolating bounding boxes from a video using detector

1 visualización (últimos 30 días)
Shirshak
Shirshak el 27 de En. de 2023
Editada: Ajay Gajulapally el 2 de Mzo. de 2023
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 comentarios
Shirshak
Shirshak el 27 de En. de 2023
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 el 3 de Feb. de 2023
hi team, did you get any answers on this

Iniciar sesión para comentar.

Respuestas (1)

Ajay Gajulapally
Ajay Gajulapally el 2 de Mzo. de 2023
Editada: Ajay Gajulapally el 2 de Mzo. de 2023
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!

Categorías

Más información sobre Tracking and Motion Estimation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by