Display the different size of preview image from that of the captured images.

Illustration
John Smith - 2022-02-07T11:16:33+00:00
Question: Display the different size of preview image from that of the captured images.

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?

Expert Answer

Profile picture of Prashant Kumar 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

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!