在matlab中将视频分割成图像 [英] splitting video into images in matlab

查看:670
本文介绍了在matlab中将视频分割成图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题。我的问题是我想从avi视频中分割出所有图像帧。首先我使用了aviread()函数,它给了我内存不足的错误。然后从在线帮助我使用mmreader()和read()函数来分割图像帧,但问题是从read()函数读取的图像无法用imshow()函数显示。我有以下代码片段,

I am on a problem. My problem is that I want to split all image frames from an avi video. First of all I used aviread() function it gives me the out of memory error. Then from online help I were using mmreader() and read() function to split image frames, but the problem is read images from read() function could not be showed with imshow() function. I have the following code snippet,

function test()
   A='G:\ims\avi\nh.avi';
   B=mmreader(A);
   ims=read(B,[2000 2200]);
   figure(1),imshow(ims(1));
end

我希望此代码会显示第一个图像帧,但事实并非如此。在这段代码中,我没有内存不足错误,因为我只读了200帧。但是当我尝试读取所有帧时问题仍然存在。所以主要是我有以下两个问题,

I hoped this code would show the first image frame but it does not. In this code I am free of out of memory error because I only read 200 frames. But the problem still remains when I try to read all the frames. So mainly I have the following two problems,


  1. 如何使用mmreader()和read()摆脱内存不足的问题?

  2. 为什么上面的imshow()不显示图像框架?


推荐答案

要消除内存不足错误,请考虑读取循环内部的单个帧,如mmreader文档( doc mmreader )中所示:

To get rid of the out of memory error consider reading in a single frame inside of a loop as shown in the mmreader documentation (doc mmreader):

for k = 2000 : 2200
    ims = read(B, k);
end

原因 imshow 不工作的是读取(...)返回的值是高度x宽度x颜色x NumFrames其中高度是视频的高度,宽度是宽度视频,颜色是颜色的数量(通常为3),NumFrames是您读取的帧数。

The reason imshow is not working is that the value returned by read(...) is Height x Width x Colors x NumFrames Where Height is the height of the video, Width is the width of the video, Colors is the number of colors (usually 3) and NumFrames is the number of frames you read.

要显示第一帧使用:

imshow(ims(:,:,:,1));

这篇关于在matlab中将视频分割成图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆