필터 지우기
필터 지우기

how do i get a webcam to capture an image and store the image in a folder and continuously do so while changing the file name for each new image?

조회 수: 8 (최근 30일)
this is what i have tried to use so far to save captured image but it hasnt worked...
counter = 1;
baseDir = 'C:\Users\Nakk\Documents\MATLAB';
baseName = 'Nakk_'; %Nakk is the name i have chosen for the image files
newName = [baseDir baseName num2str(counter) '.jpg'];
while exist(newName,'file')
counter = counter + 1;
newName = [baseDir baseName num2str(counter) '.jpg'];
end
imwrite(img, newName);
  댓글 수: 2
vasundra wazir
vasundra wazir 2020년 4월 16일
can u help me the code. i want to crop the image in gui and save the image in the folder but its nit showing in the axes the image and is not saving in folder. kindly help me with this . its important.
hold on
for i=1:size(bbox,1)
rectangle('position', bbox(1,:), 'Linewidth', 5,' Linestyle', '-','Edgecolor','r');
end
hold off
N=size(bbox,1);
handles.N=N;
counter= 1;
for i=1:N
Face=imcrop(img,bbox(i,:));
axes(handles.axes2);
imshow(Face);
savenam= strcat('E:\matlab\Face Recognition & Image Processing System\R_TrainDatabase', num2str(counter));
baseDir = 'E:\matlab\Face Recognition & Image Processing System\R_TrainDatabase';
newName = [ baseDir savenam num2str(counter) ' .jpg'];
handles. face= face;
while exits(newName, 'file')
counter = counter +1;
newName = [baseDir num2str(counter) '.jpg'];
end
face= imresize(face, [140 180]);
Fac=rgb2gray(face);
imwrite(Fac, newName);
axes(handles.axes2);
imshow(Face);
end
Walter Roberson
Walter Roberson 2020년 4월 17일
savenam= strcat('E:\matlab\Face Recognition & Image Processing System\R_TrainDatabase', num2str(counter));
That already has counter as part of it, and then you put the counter in again
newName = [ baseDir savenam num2str(counter) ' .jpg'];

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

채택된 답변

Jan
Jan 2014년 3월 24일
편집: Jan 2014년 3월 24일
Notice that your baseDir does not end with a file separator, such that Matlab checks for the files "C:\Users\Nakk\Documents\MATLABNakk_1.jpg" etc.
Better use fullfile instead of the concatenation of the path with [ and ]:
newName = fullfile(baseDir, sprintf('%s%d.jpg', baseName, counter));
I prefer sprintf instead of num2str for such cases.
  댓글 수: 1
Nakk Mungofa
Nakk Mungofa 2014년 3월 25일
편집: Nakk Mungofa 2014년 3월 25일
oh wow thanks! all the images i was capturing were going into the documents folder and saved as MATLABNakk_1!instead of the MATLAB folder... (its always the smallest details)
alrite thanks for the heads up will try using sprintf

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

추가 답변 (1개)

karem nessem
karem nessem 2017년 3월 29일
the iamge isn't save ..just black

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by