1.matlab从摄像头获取图像方法:
首先是必须安装相应的插件。然后具体代码如下:
vid = videoinput('winvideo', 1,'YUY2_640x480');%获取视频,并且设置分辨率为640*480%set(vid,'ReturnedColorSpace','rgb');%色调为rgb%preview(vid);%预览%pausestart(vid);for(i=1:10) getpic=getsnapshot(vid); filename=int2str(i); filename=[filename,' Look At This.jpg'] imwrite(getpic,filename); pause(0.5);%每0.5秒截取一张图片%endstop(vid);closepreview(vid);delete(vid);clear
2.图像导入到matlab,且对图像进行灰度处理和提取轮廓处理,代码如下:
[FileName,PathName] =uigetfile('*.jpg','Select Jpg File') ;abc=fullfile(PathName,FileName);%选择图像并保存在abc中I = imread(abc);imshow(I);%读取并打开图片I1=rgb2gray(I);%读取灰度figureimshow(I1);BW2 = edge(I1,'Sobel');%提取轮廓figureimshow(BW2);