如何使用MATLAB在定时间隔获取图像? [英] How do I Acquire Images at Timed Intervals using MATLAB?

查看:818
本文介绍了如何使用MATLAB在定时间隔获取图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个MATLAB初学者,我想知道如何可以从我的相机获取并保存20图像,每隔5秒。非常感谢。

I'm a MATLAB beginner and I would like to know how I can acquire and save 20 images at 5 second intervals from my camera. Thank you very much.

推荐答案

要获取图像,相机是否有一些文件化的方法来控制它从计算机? MATLAB支持链接到图书馆外部

To acquire the image, does the camera comes with some documented way to control it from a computer? MATLAB supports linking to outside libraries. Or you can buy the appropriate MATLAB toolbox as suggested by MatlabDoug.

要保存图像, IMWRITE 可能是最简单的选项。

To save the image, IMWRITE is probably the easiest option.

一个简单的 FOR 循环与暂停会大大提供您所需的工作量:

To repeat the action, a simple FOR loop with a PAUSE will give you roughly what you want with very little work:

 for ctr = 1:20
   img = AcquireImage(); % your function goes here
   fname = ['Image' num2str(ctr)]; % make a file name
   imwrite(img, fname, 'TIFF');
   pause(5); % or whatever number suits your needs
 end

间隔,您必须深入了解 TIMER s。这里有一个简单的例子:

If, however, you need exact 5 second intervals, you'll have to dive into TIMERs. Here's a simple example:

function AcquireAndSave
  persistent FileNum;
  if isempty(FileNum)
    FileNum = 1;
  end
  img = AcquireImage();
  fname = ['Image' num2str(FileNum)];
  imwrite(img, fname, 'TIFF');
  disp(['Just saved image ' fname]);
  FileNum = FileNum + 1;
end

>> t = timer('TimerFcn', 'ShowTime', 'Period', 5.0, 'ExecutionMode', 'fixedRate');
>> start(t); 
...you should see the disp line from AcquireAndSave repeat every 5 seconds...
>> stop(t);
>> delete(t);

这篇关于如何使用MATLAB在定时间隔获取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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