2017-04-13 11 views
1

在MATLAB中读取视频文件的有效方式(意思是使用较少的循环和较短的运行时间)是什么意思,例如:vid1.wmv,例如具有此规格(长度:5分钟,帧宽度:640,帧高度:480,帧速率:30帧/秒)并且提取所有像素具有相同颜色(例如:黑色)并具有容差的帧的时间戳。 以下是我的代码,非常耗时。每个框架大约需要三分钟!如何在MATLAB中以相同颜色有效找到所有像素的视频帧?

clear 
close all 
clc 

videoObject = VideoReader('vid1.wmv'); 
numFrames = get(videoObject, 'NumberOfFrames'); 
all_same_color_frame=[]; 
for i=1:numFrames 
    frame = read(videoObject,i); % reading the 10th frame 
    W = get(videoObject, 'Width'); 
    H = get(videoObject, 'Height'); 
    q=1; 
    for j=1:H 
     for k=1:W 
      rgb(q).pixl(i).frm = impixel(frame,j,k); 
      q=q+1; 
     end 
    end 
    Q=1; 
    for x=1:q-1 
     if std(rgb(x).pixl(i).frm)==0 % strict criterion on standard deviation 
      Q=Q+1; 
     end 
    end 
    if Q>0.9*q % if more than 90 percent of all frames had the same color 
     all_same_color_frame = [all_same_color_frame i]; 
    end 
end 

在此先感谢

+0

你问的是如何有效地找到它们或者只是如何找到它们?你目前的代码或方法是什么样的? –

+0

什么是“高效”?什么是“最简单”?没有适当的语境,这些话就没有任何意义 – Piglet

+0

我加了我的解决方案,但速度太慢了! – Remy

回答

0
videoObject = VideoReader('vid1.wmv'); 
b=[];t=[]; 
i=1; 
while hasFrame(videoObject) 
    a = readFrame(videoObject); 
    b(i) = std2(a); % standard deviation for each image frame 
    t(i) = get(videoObject, 'CurrentTime'); % time stamps of the frames for visual inspection 
    i=i+1; 
end 
plot(t,b) % visual inspection 

以上是我使用标准偏差来检测几乎所有像素都在相同颜色的帧的解决方案。

0

因为没有相关性,您可以并行化的循环框架。

这并不完全清楚你想要做什么,但你应该一定要尝试每帧计算你的标准偏差(或任何度量)(2D),而不是每次都将值收集到一个向量中,因为这样会不高效。

相关问题