Matlab摄像头视频基本处理

1、读取摄像头python

1.首先保证摄像头及其驱动正确在电脑上安装
2.简单的代码显示驱动摄像头,并显示:

ide

vid = videoinput('winvideo',1);
preview(vid);

3.默认显示彩色rgb图像,可用下面代码转换为灰度图像:

set(vid,'ReturnedColorSpace','grayscale');

若要还原为彩色图像,即把上面的grayscale换成rgb

2、获取摄像头图像函数

image = getsnapshot(vid);%得到图像矩阵
figure;
imshow(image);%显示该幅图片

3、保存视频spa

writerObj = VideoWriter( [filename '.avi'] );%建立.avi文件
writerObj.FrameRate = N;%设置视频帧率
open(writerObj);

figure;
for ii = 1: nframe
    frame = getsnapshot(vid);
    imshow(frame);
    f.cdata = frame;
    f.colormap = [];
    writeVideo(writerObj,f);
end

close(writerObj);

4、摄像头深入理解
code

    imaqhwinfo()函数返回一个结构体,里面包含DeviceID和DeviceInfo,DeviceID存储着电脑上全部可用摄像头的ID,每一个ID对应一个摄像头。DeviceInfo中存储着每一个摄像头的信息,最主要的就是摄像头所支持的视频格式。经过下面代码能够获得DeviceID和DeviceInfo中支持的格式信息:
orm

cam_info = imaqhwinfo('winvideo');
cam_info.DeviceInfo.DeviceID
cam_info.DeviceInfo.SupportedFormats
获得支持的格式信息后,便可加到第一个代码中去了:

vid = videoinput('winvideo',1,'Formats');
相关文章
相关标签/搜索