vid2

vid = videoinput('winvideo',1,'YUY2_640x480');
preview(vid)
pause(1)
set(vid,'ReturnedColorSpace','rgb');
img = getsnapshot(vid);
% rgb = ycbcr2rgb(img); % don't need to convert colorspace earlier
imshow(img);
width = 29; % enter width of target
height = 15; % enter height of target
d = input('enter distance: ');
data = getsnapshot(vid);
n = 1;
dist(n) = d;
fprintf('picture %d distance %g\n',n,d);
for k = 1:40;
    d = input('enter distance: ');
    if d<=0
        break
    end
    img = getsnapshot(vid);
    n = n + 1;
    data(:,:,:,n) = img;
    dist(n) = d;
    fprintf('picture %d distance %g\n',n,d);
    imshow(img);
end
imaqmontage(data);
save test3 data dist width height
delete(vid);
clear all;