Question
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
Prashant Kumar
PhD Expert
Answered Nov 20, 2025
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
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related preview Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →