metlab控制摄像头操作笔记(一)基础操作

%显示已经按装的摄像头的硬件信息

>> imaqInfo=imaqhwinfo
Warning: No Image Acquisition adaptors found. Image acquisition adaptors may be available as downloadable
support packages. Open Support Package Installer to install additional vendors. 


imaqInfo = 


    InstalledAdaptors: {}
        MATLABVersion: '8.4 (R2014b)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.8 (R2014b)'

提示看不到摄像头。按提示点击链接安装后


>> imaqInfo=imaqhwinfo


imaqInfo = 


    InstalledAdaptors: {'dcam'}
        MATLABVersion: '8.4 (R2014b)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.8 (R2014b)'


>> 



我的笔记本自带一个USB的摄像头,想通过来自带的摄像头来拍照和保存图片

>> info=imaqhwinfo



info = 


    InstalledAdaptors: {'dcam'}
        MATLABVersion: '8.4 (R2014b)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.8 (R2014b)'


需要在supportpackageInstaller里面选择 OS Generic Video Interface安装后就可以看到摄像头:


>> info=imaqhwinfo


info = 
  InstalledAdaptors: {'dcam'  'winvideo'}
        MATLABVersion: '8.4 (R2014b)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.8 (R2014b)'


>>

%可以看到自带的摄像头的名称为winvideo

%查看winvideo摄像头的DeviceID后获取相机对象

>> winvideoinfo=imaqhwinfo('winvideo')

winvideoinfo = 

       AdaptorDllName: 'C:\MATLAB\SupportPackages\R2014b\osgenericvideointerface\toolbox\imaq\supportp...'
    AdaptorDllVersion: '4.8 (R2014b)'
          AdaptorName: 'winvideo'
            DeviceIDs: {[1]}
           DeviceInfo: [1x1 struct]


>> 

%输出相机信息

>> winvideoinfo.DeviceInfo

ans = 

       DefaultFormat: 'MJPG_1280x720'
       DeviceFileSupported: 0
                DeviceName: 'Integrated Camera'
                  DeviceID: 1
     VideoInputConstructor: 'videoinput('winvideo', 1)'
    VideoDeviceConstructor: 'imaq.VideoDevice('winvideo', 1)'
          SupportedFormats: {1x15 cell}

>> 

%创建相机实例

>> vid=videoinput('winvideo',1,'MJPG_1280x720');

>> set(vid,'TriggerRepeat',Inf);
>> set(vid,'FramesPerTrigger',1);
>> set(vid,'FrameGrabInterval',1);
>> set(vid,'ReturnedColorSpace','rgb');
>> vidRes=get(vid,'VideoResolution');
>> nBands=get(vid,'NumberOfBands');
>> hImage=image(zeros(vidRes(2),vidRes(1),nBands));
>> preview(vid,hImage);

这样摄像头就显示出来了。


也可以通过APPS-》Image Acquisition来查看已经安装的摄像头信息列表。



你可能感兴趣的:(MatLab)