my code is here:
vid = videoinput('winvideo',1,'YUY2_640x480');
triggerconfig(vid ,'manual');
set(vid, 'TriggerRepeat',inf);
set(vid, 'FramesPerTrigger',1);
vid.ReturnedColorspace = 'rgb';
vid.Timeout = 6;
start(vid);
while(1)
facedetector = vision.CascadeObjectDetector;
trigger(vid);
img = getdata(vid, 1);
bbox = step(facedetector, img);
hello = insertObjectAnnotation(img,'rectangle',bbox,'Face');
imshow(hello);
imwrite(img(bbox(2):bbox(2)+bbox(4),bbox(1):bbox(1)+bbox(3)),'Faceimage.jpg')
end
stop(vid),clear vid