save snapshot image in a variable within a loop!!

조회 수: 4 (최근 30일)
Khaled Al-Faleh
Khaled Al-Faleh 2017년 4월 4일
댓글: Jan 2017년 4월 4일
please need help in this why the data(i) variable in while loop give me an error here I want to take a picture after each 5 second and I need it continuous so I used while(1) ...
vid = videoinput('winvideo',1);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb');
i = 0;
while(1)
data(i) = getsnapshot(vid);
imshow(data(i));
i=i+1;
pause(5);
end
  댓글 수: 1
Jan
Jan 2017년 4월 4일
You mention an error. Then please post the message. It is easier to suggest an improvement than to guess the problem.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2017년 4월 4일
Get rid of the (i) and have just data, or better yet, a more descriptive filename:
for f = 1 : 1000 % view and save 1000 frames then quit.
thisFrame = getsnapshot(vid);
imshow(thisFrame);
drawnow;
baseFileName = sprintf('Frame %3.3d.png', f);
fullFileName = fullfile(folder, baseFileName);
imwrite(thisFrame, fullFileName);
end

추가 답변 (1개)

Joseph Cheng
Joseph Cheng 2017년 4월 4일
편집: Joseph Cheng 2017년 4월 4일
from what i see get snapshot returns a NxMx(1 for mono 3 for color) and you're trying to stuff it into a 1x1. what you should try is i=1 for start as data(0) isn't how matlab works. and put data as data(:,:,i) for monochrome as you'll be putting a NxM into data's NxMx1 indexes. change the data() into a cell array if you want to store it as an rgb image.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by