Hi, I have a question about webcam Image Capture and Preview. The following is my simple code. This cpde captures images from the webcam every one second while displaying the preview image. ---------------------------------------------------------------------- cap1 = videoinput('winvideo', ID_num1,'YUY2_1920x1080'); preview(cap1) for 1 = 1:1000 frame1 = getsnapshot(cap1); imwrite(frame1,'title','.jpg'); pause(1) end ---------------------------------------------------------------------- The preview image from my webcam is 1920x1080. Instead, I would like to display the preview image 320x240 while capturing the images from the webcam for 1920x1080. Is there any suggestion or any way to solve my problem?
Prashant Kumar answered .
2025-11-20
What you basically want is a preview window that is smaller. You can achieve that by forcing the figure (and axes) to be a smaller dimension. Try something like this:
cap1 = videoinput('winvideo', ID_num1,'YUY2_1920x1080');
figure('Units', 'pixels', 'Position', [100 100 340 260]);
axes('Units', 'pixels', 'Position', [10 10 320 240]);
vidRes = get(cap1, 'VideoResolution');
nBands = get(cap1, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
preview(cap1, hImage)
for ii = 1:1000
frame1 = getsnapshot(cap1);
imwrite(frame1,sprintf('image%03d.jpg', ii));
pause(1)
end