every time i capture an image,previous one gets deleted.please tell me how to save images with different names every time i capture.and also tell me how to load any image by selecting from the list of captured images.
i am using matlab gui to capture pictures through webcam. i dont know how to save images with different names..
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
PLEASE HELP
my code is
function pbPreview_Callback(hObject, eventdata, handles)
vid = videoinput('winvideo', 1, 'YUY2_176x144');
% only capture one frame per trigger, we are not recording a video
vid.FramesPerTrigger = 1;
% output would image in RGB color space
vid.ReturnedColorspace = 'rgb';
% tell matlab to start the webcam on user request, not automatically
triggerconfig(vid, 'manual');
% we need this to know the image height and width
vidRes = get(vid, 'VideoResolution');
% image width
imWidth = vidRes(1);
% image height
imHeight = vidRes(2);
% number of bands of our image (should be 3 because it's RGB)
nBands = get(vid, 'NumberOfBands');
% create an empty image container and show it on axPreview
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview);
% begin the webcam preview
preview(vid, hImage);
% --- Executes on button press in pbCapture.
function pbCapture_Callback(hObject, eventdata, handles)
% hObject handle to pbCapture (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
vid = videoinput('winvideo', 1, 'YUY2_176x144');
vid.FramesPerTrigger = 1;
vid.ReturnedColorspace = 'rgb';
triggerconfig(vid, 'manual');
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = get(vid, 'NumberOfBands');
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview)
preview(vid, hImage);
x=1;
%while 1
% prepare for capturing the image preview start(vid);
% pause for 3 seconds to give our webcam a "warm-up" time
pause(3);
% do capture!
trigger(vid);
% stop the preview
stoppreview(vid);
% get the captured image data and save it on capt1 variable
capt1 = getdata(vid);
% now write capt1 into file named captured.png
imwrite(capt1, 'captured.png');
% just dialog that we are done capturing
warndlg('Done!');
function pushbutton3_Callback(hObject, eventdata, handles)
imshow('C:\Documents and Settings\Anita\My Documents\MATLAB\captured.png');
3 commentaires
Jan
le 30 Jan 2013
Modifié(e) : Jan
le 30 Jan 2013
Please format your code properly. Important information should be added to the question and not provided in a comment. Meaningful tags are important also: almost all questions concern "matlab code" and your problem is not related to "matlab gui" as far as I understand. So please add meaningful tags, which helps to classify the question. Thanks.
Réponses (1)
Jan
le 30 Jan 2013
Modifié(e) : Jan
le 30 Jan 2013
Simply add a counter to the program:
counter = 0;
...
counter = counter + 1;
imwrite(capt1, sprintf('captured%.3d.png', counter));
Loading the image can be implemented easily also:
[fileName, filePath] = uigetfile('*.png');
if ~ischar(fileName)
return;
end
Img = imread(fullfile(filePath, fileName));
2 commentaires
Voir également
Catégories
En savoir plus sur Image Preview and Device Configuration dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!