vid=videoinput('winvideo',2,'YUY2_640x480');
preview(vid);%打开拍摄窗口
start(vid);%开始拍摄
pic=getsnapshot(vid);
ref=ycbcr2rgb(pic);
for i=1:1000
pic=getsnapshot(vid);%抓图
getpic=ycbcr2rgb(pic);
if ( ( sum(sum(abs(getpic(:,:,1)-ref(:,:,1))))>=640*480*3 ) ||...
( sum(sum(abs(getpic(:,:,2)-ref(:,:,2))))>=640*480*3 ) ||...
( sum(sum(abs(getpic(:,:,3)-ref(:,:,3))))>=640*480*3 ) )
disp(datestr(now));
%执行保存抓拍图片
filename=int2str(i);
filename=[filename,'.jpg'];
%filename=[filename(end-7:end-6),filename(end-4:end-3),filename(end-1:end),'.j pg'];
imwrite(getpic,filename);
ref=getpic;
%执行报警声
load chirp;
player = audioplayer(y, Fs);
play(player);
%提示危险
hmb=msgbox(' 请注意,敌人入侵!','消息对话框','warn');
end
pause(0.1);
end
stop(vid);%停止拍摄
closepreview(vid);%关闭拍摄窗口
delete(vid);
clear;