Image acquisition in MATLAB at specified frame rate and save images as TIFF files on hard disk

試著忘記壹切 提交于 2020-01-05 12:13:46

问题


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!!


回答1:


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


来源:https://stackoverflow.com/questions/25145526/image-acquisition-in-matlab-at-specified-frame-rate-and-save-images-as-tiff-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!