问题描述
我正在尝试使用MATLAB控制Point Gray Grasshopper3(USB3)摄像机(GS3-U3-41C6NIR-C)来获取图像.我需要以定义的帧速率(例如12 FPS)采集图像,持续80秒,然后以TIFF格式(灰度)将图像安全保存在计算机硬盘上.我安装了"pointgrey"和"winvideo"适配器,以及最新版本的Matlab和图像采集工具箱". (作为操作系统,我使用Windows 7 Professional 64位.)
I am trying to acquire images with MATLAB controlling a Point Grey Grasshopper3 (USB3) camera (Model GS3-U3-41C6NIR-C). I need to acquire images at a defined frame rate (e.g. 12 FPS) for a duration of 80 seconds and safe the images on the hard disk of my computer in TIFF format (grayscale). I have the 'pointgrey' and 'winvideo' adaptors installed and the latest version of Matlab and the Image Acquisition Toolbox. (As OS, I use Windows 7 Professional 64-bit.)
>> imaqhwinfo
ans =
InstalledAdaptors: {'pointgrey' 'winvideo'}
MATLABVersion: '8.3 (R2014a)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '4.7 (R2014a)'
- 如何将帧速率设置为每秒12帧(或类似值)?
- 如何将获取的图像作为TIFF(灰度)文件存储在HD上?到目前为止,我只能将图像存储为AVI文件,然后再转换为.tif文件.
有人可以帮我吗?非常感谢您的帮助!
Can anyone help me on this? Your help is highly appreciated!!
推荐答案
您的网络摄像头具有一组定义的帧速率,您可以选择这些帧速率,但不能将其设置为所需的任何随机帧速率.您可以找到帧速率集并通过使用功能getselectedsource()
并以视频对象作为输入来更改它们.
Your webcam has a defined set of framerates that you can choose from, you can't set it to any random frame rate you want. You can find the set of frame rates and change them by using the function getselectedsource()
with your video object as input.
src = getselectedsource(vid)
Display Summary for Video Source Object:
Index: SourceName: Selected:
1 'input1' 'on'
结构src
现在包含并控制许多网络摄像头属性,其中包括帧频.使用功能propinfo()
查看当前和可用的帧速率.
The structure src
now contains and controls many of the webcam properties, frame rate among them. Use the function propinfo()
to see the current and available frame rates.
propinfo(src,'FrameRate')
ans =
Type: 'string'
Constraint: 'enum'
ConstraintValue: {'30.0000' '15.0000'}
DefaultValue: '30.0000'
ReadOnly: 'whileRunning'
DeviceSpecific: 1
对于我的网络摄像头,我有两个选项,帧速率为30或15.要更改帧速率,请执行以下操作:
For my webcam I have two options, a framerate of 30 or 15. To change the frame rate do:
set(src, 'FrameRate','15');
要测试帧速率,我们可以获取一些图像并记录速率
To test the frame rate we can acquire some images and record the rate
vid.FramesPerTrigger = 50;
set(src, 'FrameRate','30')
start(vid); [frames, timeStamp] = getdata(vid);
1/mean(diff(timeStamp))
ans =
29.1797
set(src, 'FrameRate','15')
start(vid); [frames, timeStamp] = getdata(vid);
1/mean(diff(timeStamp))
ans =
15.0109
要将图像另存为.tiff,请在循环播放帧时使用imwrite()
功能,并使用sprintf()
以避免覆盖图像.
To save the images as .tiff use the imwrite()
function while looping over the frames and use sprintf()
to avoid overwriting the images.
for ii=1:size(frames,4)
imwrite(frames(:,:,:,ii),sprintf('web%i.tiff',ii));
end
这篇关于在MATLAB中以指定的帧频采集图像并将图像作为TIFF文件保存在硬盘上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!