Matlab获取摄像头信息并打开摄像头

1、打开摄像头的代码如下:

source.vid = videoinput('winvideo', 1,'YUY2_320x240');

set(source.vid,'ReturnedColorSpace','grayscale');
vidRes = get(source.vid, 'VideoResolution');
nBands = get(source.vid, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
preview(source.vid, hImage);

2、获取摄像头相关信息如下:

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
% >> win_info=imaqhwinfo('winvideo')%我们看看第二适配器的具体参数
%
% win_info =
%
%        AdaptorDllName: [1x81 char]%适配器dll文件绝对路径
%     AdaptorDllVersion: '3.1 (R2008a)'%适配器dll文件版本
%           AdaptorName: 'winvideo'%适配器名称
%             DeviceIDs: {[1]}%设备ID号,这个我们经常需要用到
%            DeviceInfo: [1x1 struct]%设备信息,这里主要是图像获取设备的一些参数,比较重要
%
% %====================下面我们了解下,这个图像获取设备到底有哪些的详细信息吧====================
%
% >> win_info.DeviceIDs
%
% ans =
%
%     [1]
%
% >> dev_win_info=win_info.DeviceInfo
%
% dev_win_info =
%
%           DefaultFormat: 'RGB24_320x240'%获取图片的默认格式
%     DeviceFileSupported: 0
%              DeviceName: 'USB PC CAMERA P227'%设备名称
%                DeviceID: 1%设备号
%       ObjectConstructor: 'videoinput('winvideo', 1)'%对象构建方式,这个绝大部分都是一样的
%        SupportedFormats: {1x12 cell}%获取的图像支持格式,一般都有好多种,上面的DefaultFormat只是默认格式而已
%
% %==================================看看图像获取设备支持的图像格式==================================
%
% >> dev_win_info.SupportedFormats%可以看到我的PC上的摄像头支持下面12中图片格式
%
% ans =
%
%   Columns 1 through 5
%
%     'I420_160x120'    'I420_176x144'    'I420_320x240'    'I420_352x288'    'I420_640x480'
%
%   Columns 6 through 9
%
%     'RGB24_1280x960'    'RGB24_160x120'    'RGB24_176x144'    'RGB24_320x240'
%
%   Columns 10 through 12
%
%     'RGB24_352x288'    'RGB24_640x480'    'RGB24_800x600'
%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5

发布了60 篇原创文章 · 获赞 15 · 访问量 66万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章