![](/img/trans.png)
[英]how to display the frame difference output of all the frames in video using matlab
[英]How to analyse video frames in parallel using Matlab?
我正在逐帧处理大型视频文件。 每个帧的处理都独立于其他帧(解压缩后),并且计算量大,因此我认为并行处理将是加快分析速度的好方法。 虽然我已经教自己使用并行循环的基础知识,但是在将parfor的细节与VideoReader对象结合在一起时遇到了问题。 在我看来,我想像这样运行的代码
video = VideoReader('video.mp4');
parfor ii = 1 : 90000
frame = read(video, ii);
...analysis on frame...
end
但是这警告我不要使用read(),因为它将在将来的版本中删除,因此我唯一知道的替代方法是使用frameRead()。 但是frameRead使用VideoReader对象的CurrentTime属性,该属性会在每次调用frameRead时递增自身(根据fps)。 这对于在正常循环中读取帧效果很好,但是会使parfor感到不满意,因为每个帧都依赖于根据最后一个帧增加CurrentTime。 有没有办法使用readFrame或其他方式在并行循环中访问独立的帧? 我试图通过使用循环索引和帧速率在每个循环中设置CurrentTime值,如下所示:
video = VideoReader('video.mp4');
fps = video.FrameRate
results = cell(totalFrames, 1);
parfor ii = 1 : 900000
video.CurrentTime = ii/fps;
frame = readFrame(video);
results{ii} = customAnalysisFunction(frame)
end
在此示例中,parfor用下划线/标记,并在此消息中提供了原因:
MATLAB runs loops in parfor functions by dividing the loop iterations into
groups,and then sending them to MATLAB workers where they run in parallel.
For MATLAB to do this in a repeatable, reliable manner, it must be able to
classify all the variables used in the loop. The code uses the indicated
variable in a way that is incompatible with classification
我应该采取什么步骤才能并行读取兼容的视频帧?
我应该只使用读取功能吗? 为什么我不应该这么做? Matlab还有其他视频工具吗?
经常向我建议的一种解决方案是,为什么不将视频分成单独的剪辑? 我不想这样做,因为它非常慢并且需要很多额外的步骤和文件处理。 很难相信在Matlab中没有解决此问题的方法,所以我期待您的回答!
我不希望并行阅读框架能在MATLAB中工作。 视频阅读器是一个对象,具有关于其放置位置的内部状态。 您可能会尝试使用该对象的副本。 看一下这个: http : //mathworks.com/help/matlab/ref/matlab.mixin.copyable-class.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.