在Matlab中,将图像写入AVI而不使用VideoWriter进行显示 [英] In Matlab, writing images to AVI without displaying using VideoWriter

查看:1254
本文介绍了在Matlab中,将图像写入AVI而不使用VideoWriter进行显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将循环中的图像写入AVI文件。现在,我正在使用VideoWriter和getframe来实现这一目标。代码通常是这样的:

I'm trying to write images within a loop to an AVI file. Right now, I'm using VideoWriter and getframe to achieve that goal. The code generally goes something like this:

FoodVideo = VideoWriter('tempp.avi');
FoodVideo.FrameRate = 25;
open(FoodVideo);
hh=figure('Visible','off');
for i=1:20
  imshow(example_image{i});
  hold on;
  text(100,100,sprintf('Frame Number: %d',i));
  hold off;
  currFrame = getframe(hh);
  writeVideo(FoodVideo,currFrame);
end
close(FoodVideo);

问题是getframe在写入之前会显示图像。
我想不出将文本合并到图像数据中的方法,所以我消除了这种处理问题的方式(使用im2frame ...)。
我知道我可以使用avifile和addframe,但我想使用VideoWriter,因为matlab说avifile会被删除...
有没有办法用VideoWriter编写图像而不先显示?

The problem is that getframe displays the image before writing it. I can't think of a way of incorporating the text into the image data, so I eliminated that way of handling the matter (using im2frame...). I know I can use avifile and addframe, but I want to use VideoWriter because matlab says avifile will be removed... Is there any way to write the images using VideoWriter without displaying first?

另一个相关的问题:
当我运行我的代码时,我似乎抓住了我的屏幕而不是数字;我最近换了一台电脑,这开始只发生在新电脑上。有没有人知道为什么会这样?

Another related question: When I run my code, it seems like I capture my screen instead of the figure; I recently switched a computer, and this started happening only in the new computer. Does anyone have a clue as to why that might be?

谢谢,
Aviram

Thanks, Aviram

推荐答案

经过一番搜索,我找到了解决办法。我正在使用硬拷贝功能将文本合并到图像数据中,然后使用im2frame我可以将其更改为适合与VideoWriter一起使用的格式。这似乎完美无缺:

I managed to find a solution after some searching. I am using the hardcopy function to incorporate the text into the image data and then using im2frame I can change it into a format fit to be used with VideoWriter. This seems to work perfectly:

      orig_mode = get(hfig, 'PaperPositionMode');
      set(hfig, 'PaperPositionMode', 'auto');
      cdata = hardcopy(hfig, '-Dzbuffer', '-r0');
      set(hfig, 'PaperPositionMode', orig_mode);
      currFrame = im2frame(cdata);

这篇关于在Matlab中,将图像写入AVI而不使用VideoWriter进行显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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