1

我是 Matlab 处理的新手,我想在“for 循环”(或没有它)内读取和处理一个大型视频(超过 200k 帧)。特别是,我想:

  1. 使用 VideoReader 阅读视频,
  2. 将视频细分为每个 1000 帧的 n-epoch,
  3. 处理1000帧的每个epoch,读取:epoch的第一帧,跳过两帧,读取帧,跳过两帧,以此类推(例如i=1:3:nFrames),
  4. 考虑到每个时代,我需要将读取的每个“RGB 帧”转换为 im2bw
  5. 转换后,我需要考虑第一个视频帧(“mov(1,1).cdata”)和在该时期内读取的每一帧,进行“corr2”2D 互相关,
  6. 将“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
4

2 回答 2

1
于 2012-07-30T15:04:38.447 回答
0
% create video handle and get number of frames
vidObj = VideoReader(video_file);
nFrames = get(vidObj, 'NumberOfFrames');

blocksize = 1000;
BlocksIDs = 1:blocksize:nFrames;
nBlocks = numel(BlocksIDs);

frame_step = 3;

% cell array with all correlations values grouped by block
xcorrs_all_blocks = cell(1, nBlocks);

for j = 1 : nBlocks

    % if this is the last block, process until the last frame
    if j == nBlocks
        last_frame = nFrames;
    % otherwise, read until next block
    else
        last_frame = BlocksIDs(j + 1);
    end
    % compute the frame numbers that we want to look at
    frame_indices = BlocksIDs(j) : frame_step : last_frame;
    nFrames = numel(frame_indices);

    first_frame = [];
    % pre-allocate array holding the in-block corr2 values.
    xcorrs_this_block = nan(1, nFrames-1);

    for k = 1 : nFrames

        % read-in raw frame from video file.
        raw_frame = read(vidObj, frame_indices(k));            
        % determine level for bw conversion - this might help.
        level = graythresh(raw_frame);
        raw_frame = im2bw(raw_frame, level);

        if k == 1
            % save current frame as first frame for later corr2 processing
            first_frame = raw_frame;
        else
            % calc the correlation between the first frame in the block and each successive frame
            xcorrs_this_block(k-1) = corr2(first_frame, raw_frame);
        end


    end

    % save all xcorr values into global cell array.
    xcorrs_all_blocks{j} = xcorrs_this_block;

end
于 2012-07-30T13:57:32.953 回答