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)'
- How can I set the frame rate at 12 frames per second (or a similar value)?
- How can I store the acquired images on my HD as TIFF (grayscale) files? So far, I was only able to store images as AVI-files and then subsequently transform into .tif files.
Can anyone help me on this? Your help is highly appreciated!!
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'
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
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
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