该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
clc;
clear all;
imaqmem(30000000); %申请内存空间
obj = videoinput('winvideo',1,'RGB24_800x600')%这里我们使用默认的视频采集格式
%frame是H×W×B的矩阵。H图像高度,由ROIPosition指定;w图像宽度,由ROIPosition指定;B索线个数,由NumberOfBands指定
%====================================================================
vidRes = get(obj, 'VideoResolution');
nBands = get(obj, 'NumberOfBands');
figure()%指定预览窗体显示的figure
axes()%指定预览窗口显示的坐标系
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
preview(obj, hImage);
%====================================================================
h=figure;
i=1;
f1=0;
f2=0;
while(h)
frame = getsnapshot(obj);%获取视频的一帧
%flushdata(obj); %清除数据获取引擎的所有数据、置属性SamplesAvailable为0
frame=ycbcr2rgb(frame);%色彩空间转换
frame=double(rgb2gray(frame));
rows=600;
cols=800;
if i>3
d(:,:,l)=frame-2*f1+f2;
k=d(:,:,l);
bw(:,:,l) = im2bw(k, .2);
bw1=bwlabel(bw(:,:,l));
imshow(bw(:,:,l));%显示获取那一帧
drawnow;% 实时更新图像
end
f2=f1;
f1=frame;
i=i+1;
end
%delete(obj);
%imwrite(frame,'snap.jpg','jpg');
cou=1;
for h=1:rows
for w=1:cols
if(bw(h,w,l)>50)
toplen = h;
if (cou == 1)
tpln=toplen;
end
cou=cou+1;
break
end
end
end
disp(toplen);
coun=1;
for w=1:cols
for h=1:rows
if(bw(h,w,l)>50)
leftsi = w;
if (coun == 1)
lftln=leftsi;
coun=coun+1;
end
break
end
end
end
disp(leftsi);
disp(lftln);
widh=leftsi-lftln;
heig=toplen-tpln;
widt=widh/2;
disp(widt);
heit=heig/2;
with=lftln+widt;
heth=tpln+heit;
wth(l)=with;
hth(l)=heth;
disp(heit);
disp(widh);
disp(heig);
rectangle('Position',[lftln tpln widh heig],'EdgeColor','r');
disp(with);
disp(heth);
plot(with,heth, 'r*');
drawnow;
hold off
end;
谁可以跟我看看这程序那里错了?可以跟我改改么...
谢谢大侠了.