MATLAB之camera 入门操作
2014-11-02 20:30
176 查看
查了好些资料,本想写个简要的入门教程,却发现未能及之一二,故写简要说明,自赏之!
包含video参数初始化、预览video、获取图片和处理、保存视频!
包含video参数初始化、预览video、获取图片和处理、保存视频!
%this code includes three parts:initial and preview the camera,snap the %image and process,save the video clc close all %part 1 initial the camera vidobj = videoinput('winvideo',1,'YUY2_640x480'); triggerconfig(vidobj,'manual'); %part 2 preview the camera set(vid,'ReturnedColorSpace','grayscale'); %set gray set(vid,'ReturnedColorSpace','rgb');%set preview(vidobj);%preview the camera start(vidobj); %part 3 snap the image and process tic for i = 1:100 snapshot = getsnapshot(vidobj); frame = ycbcr2rgb(snapshot); frame = rgb2gray(frame); thd = graythresh(frame)*0.8; frame = im2bw(frame,thd); frame = ~frame; imshow(frame); end elapsedTime = toc timePerFrame = elapsedTime/1000 effectiveFrameRate = 1/timePerFrame %part 4 save the video filename = 'temp'; nframe = 120; nrate = 30;%initial the condition writerObj = VideoWriter( [filename '.avi'] ); writerObj.FrameRate = nrate ; open(writerObj); figure; for ii = 1: nframe frame = getsnapshot(vidobj); imshow(frame); f.cdata = frame; f.colormap = []; writeVideo(writerObj,f); end close(writerObj); %part 5 end the video stop(vidobj); delete(vidobj); disp('end');
相关文章推荐
- MATLAB入门学习笔记(一) 矩阵的生成及操作
- Matlab快速入门1——基础操作
- matlab 入门基本操作命令与函数
- MATLAB 7.0 学习入门 -- (练习二 矩阵和数组基本操作)
- matlab 入门基本操作命令与函数
- ASP编程入门进阶(十七):FSO组件之文件夹操作
- DataGrid的使用入门(添加、删除和修改操作)
- 7)Linux程序设计入门--线程操作
- ASP编程入门进阶(十八):FSO组件之文件操作(中)
- 一个不错的matlab入门教程
- Java语言入门 -- 第九章 Java的输入输出操作
- UNIX 系统操作入门(一)
- ASP编程入门进阶(十八):FSO组件之文件操作(上)
- 3)Linux程序设计入门--文件操作
- linux操作系统下c语言编程入门 -- (7)线程操作
- nhibernate入门系列: 对象持久化操作
- UNIX 系统操作入门(三)
- ASP编程入门进阶(十八):FSO组件之文件操作(下)
- PBDOM操作XML文档轻松入门(Easy XML with PowerBuilder Document Object Model)
- ASP编程入门进阶(十八):FSO组件之文件操作(中)