MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何使用MATLAB定时采集图像? (https://www.labfans.com/bbs/showthread.php?t=22789)

poster 2019-12-10 16:49

如何使用MATLAB定时采集图像?
 
我是MATLAB的初学者,我想知道如何以5秒的间隔从相机获取和保存20张图像。非常感谢你。


回答:
要获取图像,相机是否具有某种记录的方法可以从计算机进行控制? MATLAB支持链接到[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f23224dfi7.html"]外部库[/URL] 。或者,您可以按照MatlabDoug的建议购买合适的MATLAB工具箱。

要保存图像, [URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/imwrite.html"]IMWRITE[/URL]可能是最简单的选择。

要重复该操作,只需执行一个带有[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/pause.html"]暂停[/URL]的简单[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/brqy1c1-1.html"]FOR[/URL]循环,只需很少的工作即可大致获得所需的内容:

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 但是,如果需要精确的5秒间隔,则必须深入[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f9-38012.html"]TIMER[/URL] 。这是一个简单的例子:

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);

[url=https://stackoverflow.com/questions/1467692]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:19

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.