如何利用Matlab进行usb摄像头
首先自己的电脑有个摄像头,如果没有插上USB摄像头 ,然后再启动Matlab(顺序不可返的)。
方法:
查询USB2.0Camera 的具体参数:
输入:imaqInfo = imaqhwinfo
返回:
imaqInfo =
InstalledAdaptors: {'coreco' 'winvideo'}
MATLABVersion: '7.6 (R2008a)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '3.1 (R2008a)'
输入:winvideoinfo = imaqhwinfo('winvideo')
返回:
winvideoinfo =
AdaptorDllName: 'C:\Program Files\MATLAB\R2008a\toolbox\imaq\imaqadaptors\win32\mwwinvideoimaq.dll'
AdaptorDllVersion: '3.1 (R2008a)'
AdaptorName: 'winvideo'
DeviceIDs: {[1]}
DeviceInfo: [1x1 struct]
输入:winvideoinfo.DeviceInfo
返回:
ans =
DefaultFormat: 'YUY2_160x120'
DeviceFileSupported: 0
DeviceName: 'USB2.0 Camera'
DeviceID: 1
ObjectConstructor: 'videoinput('winvideo', 1)'
SupportedFormats: {'YUY2_160x120' 'YUY2_176x144' 'YUY2_320x240' 'YUY2_352x288' 'YUY2_640x480'}
到此为止!最后一行可以看出你的相机支持的分辨率,我的usb摄像头最高支持640*480的
在语句中设置:
vid=videoinput('winvideo',1,'YUY2_640x480');
set(vid,'TriggerRepeat',Inf);
set(vid,'FramesPerTrigger',1);
set(vid,'FrameGrabInterval',1);
%设置返回色彩……
% set(vid,'ReturnedColorSpace','rgb');
set(vid,'ReturnedColorSpace','grayscale');
%获取分辨率,色彩数目等参数
vidRes=get(vid,'VideoResolution');
nBands=get(vid,'NumberOfBands');
hImage=image(zeros(vidRes(2),vidRes(1),nBands));
preview(vid,hImage);