Matlab 读取视频并分帧保存
fileName = 'E:\数据分析-成都\20220318_175929 00_00_00-00_05_01.mp4';
obj = VideoReader(fileName);
numFrames = obj.NumFrames;% 帧的总数
for k = 1 : numFrames% 读取数据
frame = read(obj,k);
disp(k);
imwrite(frame,strcat('E:\数据分析-成都\20220318_175929 00_00_00-00_05_01\',num2str(k,'%04d'),'.jpg'),'jpg');% 保存帧
end
鼠标手动标注框出目标
function ROI=LabelBox(filename)
Mat=imread(filename);
imshow(Mat);
mouse=imrect;
pos=getPosition(mouse);% x1 y1 w h
ROI=[pos(1) pos(2) pos(3) pos(4)];
end
为了快速标注,可以遍历整个文件夹下的图片,标完一张换一张,生成一个table数据表:
function BoxTable=getAllbox(folder)
fileFolder=fullfile(folder);
dirOutput=dir(fullfile(fileFolder,'*.jpg'));
filenames={dirOutput.name}'; %列向量
rois=[];
for i=1:length(filenames)
roi=LabelBox(filenames{i});
rois=[rois;roi];
end
BoxTable=table(filenames,rois);
end