在 MATLAB 中读取视频文件的有效方法是什么(意味着使用更少的循环和更短的运行时间)例如:vid1.wmv 使用此规范(长度:5 分钟,帧宽度:640,帧高度:480,帧速率) : 30 帧/秒)并提取所有像素为相同颜色(例如:黑色)且具有容差的帧的时间戳。以下是我的代码,非常耗时。每帧大约需要三分钟!
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
提前致谢
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
以上是我使用标准偏差来检测几乎所有像素颜色相同的帧的解决方案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句