我是 Matlab 处理的新手,我想在“for 循环”(或没有它)中读取和处理一个大视频(超过 200k 帧)。我特别想:
- 使用VideoReader阅读视频,
- 将视频细分为 n 个纪元,每个纪元 1000 帧,
- 处理 1000 帧的每个 epoch,读取:该 epoch 的第一帧,跳过两帧,读取该帧,跳过两帧,依此类推(例如 i=1:3:nFrames),
- 考虑到每个纪元我需要将每个“RGB帧”读取转换为im2bw
- 转换后,我需要考虑第一个视频帧(“mov(1,1).cdata”)和该纪元内读取的每个帧,进行“corr2”2D互相关,
- 将“corr2”的结果存储到向量中。
总而言之,这就是我需要做的。谢谢你们
到目前为止,这是我关于“corr2”的信息:
for frame_ind = 1 : nFrames
mov(frame_ind).cdata = im2bw(rgb2gray(read(xyloObj,frame_ind)),0.20);
end
%% Corr2 to compare BW video frames
for frame_ind2 = 1:(frame_ind-1)
R(frame_ind2)=corr2(mov(1,frame_ind2).cdata,mov(1,frame_ind2+1).cdata);
end
TF= isnan(R);
g=sum(TF);
f=(length(R)-g);
if (g~=(length(R)))
%%If Part has errors
disp('"Part_1" has video interferences/noise/problems, see "Testresult.txt" for more information.');
else
%%If Part has not errors
displ=strcat('"Part_1" has not video interferences/noise/problems.');
end
这是我的版本:
mov = VideoReader('movie.avi');
nFrames = mov.NumberOfFrames;
len = 1000; %# epoch length
step = 3; %# step size
%# indices of each epoch
indices = bsxfun(@plus, 1:step:len, (0:ceil(nFrames/len-1))'*len); %#'
indices = num2cell(indices,2);
indices{end}(indices{end}>nFrames) = [];
%# loop over each epoch
corr_coef = cell(size(indices));
for e=1:numel(indices)
%# read first image in epoch
img1 = read(mov, indices{e}(1));
img1 = rgb2gray(img1); %# instead of im2bw(img1, graythresh(img1))
%# read rest of images in epoch
corr_coef{e} = zeros(1,numel(indices{e})-1);
for f=2:numel(indices{e})
img2 = read(mov, indices{e}(f));
img2 = rgb2gray(img2);
%# compute corr2 between the two images
corr_coef{e}(f-1) = corr2(img1,img2);
end
end
元胞数组corr_coef
包含每个时期的相关系数,其中每个单元格包含一个向量corr_coef{e}(i)
of corr2
在第一帧和第(i+1)帧之间。
请注意,如果其中一帧是恒定的(例如全黑),则 2D 相关系数只是 NaN(零除以零)formula)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)