matlab使用摄像头

demo

%% I.打开摄像头并获取图像
clear;
clc;
camList = webcamlist    % Connect to the webcam.
cam = webcam(1)         % Access specific property values
preview(cam);           % Preview video stream
img = snapshot(cam);    % Get a single frame
figure,image(img);      % Display the frame in a figure window.

% 获取5个帧
for idx = 1:5
    figure(idx+1),
    img = snapshot(cam);
    image(img);
end
clear cam               % Clearing variables

%% II.将视频记录到磁盘
cam = webcam
vidWriter = VideoWriter('frames.avi')   % Create the object and open the AVI file to be written
open(vidWriter)

% 获取和存储帧---记录20帧的视频
for index= 1:20
    img = snapshot(cam)                 % Acquire frame for processing
    writeVideo(vidWriter,img)           % Write frame to video
end

close(vidWriter)		% Clearing variables 
clear cam
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值