matlab怎么调用电脑摄像头监控拍照?求程序代码!!
1个回答
展开全部
vid=videoinput('winvideo');
set(vid,'TriggerRepeat',inf);
h=figure('units','normalized','menubar','none','numbertitle','off');
ha=axes('parent',h,'units','normalized','position',[.005 .7 .99 .925]);
axis off;
hb=uicontrol('parent',h,'units','normalized','position',[.01 .1 .199 .6],'string','Preview','callback',...
['hf=figure(''units'',''normalized'',''menubar'',''none'',''numbertitle'',''off'');'...
'axes(''parent'',hf,''units'',''normalized'',''position'',[.005 .007 .99 .99]);'...
'objRes=get(vid, ''VideoResolution'');'...
'nBands=get(vid,''NumberOfBands'');'...
'hImage=image(zeros(objRes(2),objRes(1),nBands));'...
'preview(vid,hImage);']);
hb1=uicontrol('parent',h,'units','normalized','position',[.604 .1 .198 .6],'string','Play','callback',...
['mplay(''video.avi'');'...
'pause(0.1);play(R);']);
bs=uicontrol('parent',h,'units','normalized','position',[.208 .1 .198 .6],'string','Save','callback',...
['C=questdlg(''确定保存'',''保存'',''Y'',''N'',''Y'');'...
'if C==''Y'''...
'mov=avifile(''video.avi'',''fps'',20);'...
'R=audiorecorder(44100,24,2);'...
'for i=1:80'...
'F=getframe(hf);'...
'mov=addframe(mov,F);'...
'record(R);'...
'pause(0.05);'...
'end;'...
'stop(R);mov=close(mov);'...
'msgbox(''Succeed saving!!'');'...
'end;']);
hd=uicontrol('parent',h,'units','normalized','position',[.406 .1 .198 .6],'string','Photoing','callback',...
['ph=getsnapshot(vid);'...
'figure(3);'...
'imshow(ph);'...
'c=questdlg(''是否保存'',''保存'',''Y'',''N'',''Y'');'...
'if c==''Y'''...
'imwrite(ph,''photo.png'');'...
'end;']);
hc=uicontrol('parent',h,'units','normalized','position',[.802 .1 .198 .6],'string','Delete','callback',...
['cc=questdlg(''确定要删除文件'',''删除'',''Y'',''N'',''Y'');'...
'if cc==''Y'''...
'try '...
'delete(''video.avi'');'...
'delete(''photo.png'');'...
'end;'...
'end']);
hl=uicontrol('parent',h,'units','normalized','position',[.01 .05 .09 .05],'string','Close','callback',...
['try '...
'close(h);'...
'close(hf);end']);
set(vid,'TriggerRepeat',inf);
h=figure('units','normalized','menubar','none','numbertitle','off');
ha=axes('parent',h,'units','normalized','position',[.005 .7 .99 .925]);
axis off;
hb=uicontrol('parent',h,'units','normalized','position',[.01 .1 .199 .6],'string','Preview','callback',...
['hf=figure(''units'',''normalized'',''menubar'',''none'',''numbertitle'',''off'');'...
'axes(''parent'',hf,''units'',''normalized'',''position'',[.005 .007 .99 .99]);'...
'objRes=get(vid, ''VideoResolution'');'...
'nBands=get(vid,''NumberOfBands'');'...
'hImage=image(zeros(objRes(2),objRes(1),nBands));'...
'preview(vid,hImage);']);
hb1=uicontrol('parent',h,'units','normalized','position',[.604 .1 .198 .6],'string','Play','callback',...
['mplay(''video.avi'');'...
'pause(0.1);play(R);']);
bs=uicontrol('parent',h,'units','normalized','position',[.208 .1 .198 .6],'string','Save','callback',...
['C=questdlg(''确定保存'',''保存'',''Y'',''N'',''Y'');'...
'if C==''Y'''...
'mov=avifile(''video.avi'',''fps'',20);'...
'R=audiorecorder(44100,24,2);'...
'for i=1:80'...
'F=getframe(hf);'...
'mov=addframe(mov,F);'...
'record(R);'...
'pause(0.05);'...
'end;'...
'stop(R);mov=close(mov);'...
'msgbox(''Succeed saving!!'');'...
'end;']);
hd=uicontrol('parent',h,'units','normalized','position',[.406 .1 .198 .6],'string','Photoing','callback',...
['ph=getsnapshot(vid);'...
'figure(3);'...
'imshow(ph);'...
'c=questdlg(''是否保存'',''保存'',''Y'',''N'',''Y'');'...
'if c==''Y'''...
'imwrite(ph,''photo.png'');'...
'end;']);
hc=uicontrol('parent',h,'units','normalized','position',[.802 .1 .198 .6],'string','Delete','callback',...
['cc=questdlg(''确定要删除文件'',''删除'',''Y'',''N'',''Y'');'...
'if cc==''Y'''...
'try '...
'delete(''video.avi'');'...
'delete(''photo.png'');'...
'end;'...
'end']);
hl=uicontrol('parent',h,'units','normalized','position',[.01 .05 .09 .05],'string','Close','callback',...
['try '...
'close(h);'...
'close(hf);end']);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询